Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Bullet Hole Rotation messed up! Please Help!

Discussion in 'Scripting' started by p_r1710, May 8, 2015.

  1. p_r1710

    p_r1710

    Joined:
    Apr 17, 2015
    Posts:
    5
    I'm trying to make bullet holes, but every time i shoot it creates the bullet holes at the wrong angle.


    Screenshot (1).png

    Here's the code:



    var maxDist : float = 10000000;
    var decalHitWall : GameObject;
    var floatInFrontOfWall : float = 0.01;

    function Update () {
    var hit : RaycastHit;
    if(Physics.Raycast(transform.position, transform.forward, hit, maxDist))
    {
    if(decalHitWall && hit.transform.tag == "Level Parts")
    Instantiate(decalHitWall, hit.point +(hit.normal * floatInFrontOfWall), Quaternion.LookRotation(hit.normal));
    }
    Destroy(gameObject);
    }



    Any help is appreciated!
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,999
    For rotation try,
    Code (CSharp):
    1. Quaternion.EulerAngles(hit.normal)
     
  3. p_r1710

    p_r1710

    Joined:
    Apr 17, 2015
    Posts:
    5
    Thanks for the help but now it only spawns it correctly on certain faces.

    Screenshot (2).png
     
  4. goopydoopyloops

    goopydoopyloops

    Joined:
    May 10, 2015
    Posts:
    10
    i think if you call the main function in the thing it might help idk
     
  5. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    683
  6. p_r1710

    p_r1710

    Joined:
    Apr 17, 2015
    Posts:
    5
    I'm a 7th grade kid who's trying to learn but i don't really know how to use the second parameter of lookRotaion.
    An example would be very helpful.

    Thanks for the answers though.
     
  7. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    683
    well i think i had a similar problem

    http://answers.unity3d.com/questions/681680/drawing-flat-arrows.html
    i think the problem is that you are not specifying an up direction for your look at
    there ate an infinite number of rotations from which to 'look at point'
    but only one when also specifying up direction

    another way to look at it is:
    what axis do you want to rotate about when 'look at point'

    i think
    idk :)