- Home /
Stop animation when character controller hits walls
Hi,
I'm have a character which I am moving using the standard character controller. I need to stop playing the walk cycle animation and maybe restrict movement if the player is moving into a wall. I've noticed that the Move function on the character controller returns collision flags, which you can use to determine if the sides of the character are colliding with anything, but I haven't found a way to use them, that doesn't cause jitter, when the character walks in to walls. I can't be the first to have this problem. What's the solution?
$$anonymous$$aybe try doing it by checking that your character's throttle and velocity are pointing in the same direction, but the velocity's magnitude is near zero.
Well, I can't get the velocity before I have already moved :/
Answer by ZeroSumGames · Aug 05, 2013 at 06:25 PM
I would have the walls tagged with a Tag called "walls" or what have you. Then in the character class I would have an OnCollisionEnter() function which kills the animation if the object collided with has the tag "walls".
CharacterController does not have an OnCollisionEnter(), it does however have OnControllerColliderHit(). The problem is that if you just set a flag on this collision to restrict movement and animation, then it will not collide the thus not restricting anything and it will just jump between the two causing jitter.