Search Unity

How to get the exact position and rotation of a rigidbody on collision

Discussion in 'Scripting' started by monkeybrother, Apr 21, 2013.

  1. monkeybrother

    monkeybrother

    Joined:
    Oct 14, 2010
    Posts:
    83
    I'm trying to shoot a spear and have it stick to whatever it hits. The problem is that if I use OnCollisionEnter, I seem to get the position and rotation a few frames after it hit, which makes the spears point in seemingly random directions.

    So, how can I get the exact position and rotation on the exact moment of impact? just can't figure it out.

    Thanks.
     
  2. wickedworx

    wickedworx

    Joined:
    Mar 13, 2013
    Posts:
    54
    have you made sure you've got interpolation turned on and continuous / continuous dynamic collision detection mode set on the rigid body?
     
  3. monkeybrother

    monkeybrother

    Joined:
    Oct 14, 2010
    Posts:
    83
    Hi. Yes, I've tried every combination, but it doesn't seem to make a difference.

    When I did a search I found posts saying that OnCollisionEnter registers a bit after the two colliders have touched. If that's true, there surely must be a workaround?
     
  4. ToshoDaimos

    ToshoDaimos

    Joined:
    Jan 30, 2013
    Posts:
    679
    I'm just a noob, but I have an idea. If collisions are physics, maybe the problem is that your FixedUpdate runs to slow, comparing to Update.