- Home /
Why won't standart FirstPersonController accept new position?
Hi
I wanted to move my player (standard FirstPersonController) to a spawn point when they collide with anything. The following doesn't work, and yet if I put the same line in Start() or Update() it works fine. (I've used Vector3.zero just to rule anything else out)
function OnControllerColliderHit(hit : ControllerColliderHit)
{
transform.position = Vector3.zero;
}
Answer by Mike 3 · Jul 04, 2010 at 06:31 PM
I'm wondering if you have another script moving your controller (which is probably being called in update, screwing up the above code).
That'd explain why it's showing the position correctly in the collision, but (seemingly) not persisting it
Only the standard FPSWalker script. I've found a temporary fix by using OnTriggerEnter ins$$anonymous$$d, identical code otherwise, and it works fine. Thanks.
Answer by StephanK · Jul 04, 2010 at 03:15 PM
Probably OnControllerColliderHit is never called. Check if your setup (Colliders etc.) is correct.
Yup. $$anonymous$$ore discussion: http://answers.unity3d.com/questions/13827/my-script-isnt-working-what-are-some-ways-i-can-start-debugging/13852#13852
Thanks, but I inserted: print("OnControllerColliderHit called " + transform.position.x + " " + transform.position.z); in to the above and can see that it's being called and that it's position is displayed correctly. Anything I tried within that function gets called O$$anonymous$$ except for any attempt to move the controller either directly or with controller.$$anonymous$$ove(moveDirection); Can anybody replicate this situation?