Search Unity

Way to dirty the character controller collider for physics engine?

Discussion in 'Scripting' started by cjddmut, Mar 27, 2014.

  1. cjddmut

    cjddmut

    Joined:
    Nov 19, 2012
    Posts:
    120
    I have a character controller that "dies" when it collides with a hazard tagged trigger and is then repositioned (by manually setting the transform) to a safe known location.

    This is all good except on the next frame it will register another collision event (OnTriggerStay) even though it is no longer colliding. I figure the physics engine is trying to be smart and doesn't know that the transform has been moved (especially since I did it manually).

    So is there a way to purposely dirty a collider for physics calculation updates (assuming that is indeed my problem :))?

    Thanks!
    C.J.
     
  2. JVILL

    JVILL

    Joined:
    Dec 18, 2012
    Posts:
    6
    Is it possible to use onTriggerEnter instead so the die function is only called once?

    That way, onTriggerStay isn't really needed because it's a one time event. After the initial collision, you teleport the player, and it won't run the die function again until you onTriggerEnter it again.

    I'm not a collision expert, in-fact I'm having my own collision problems here:
    http://forum.unity3d.com/threads/236706-More-Collision-Problems
     
  3. cjddmut

    cjddmut

    Joined:
    Nov 19, 2012
    Posts:
    120
    Originally I had reason for leveraging OnTriggerStay but as I went back and looked at it that reason is no longer applicable so I can use instead OnTriggerEnter.

    Though, I'm still curious if there is a way to force the physics engine to update its knowledge of where the collider is.
     
unityunity