Hello! I move the walking Persian with this:

player.transform.position += player.transform.forward * speed * Time.deltaTime; 

Naturally, I set the speed myself. The walking Persian comes up against the collider and stops, continuing to walk. How to find out that he stopped moving, in order to change the animation depending on the speed. It seems I am doing unacceptable ...

  • Compare previous coordinates with current ones. If the coordinates have not changed, then it does not move. - Pyramidhead
  • I try, even it does not work yet - Georgich
  • Capacious comment. What exactly does not work? - Pyramidhead pm
  • You can hang OnTriggerEnter at the collider or even OnCollisionEnter .... and see if the tag object that the Player crashed into, then send SendMessage to the player script ... to the method .. which is responsible for switching the animation, etc. - Alexey Shimansky
  • just tried OnCollisionEnter. Finding out nothing failed. I will try on your advice - Georgich

1 answer 1

If you use physics, and the object moves through a change of position in the transform.position this is not at all good, you are disturbing the work of PhysX. Either you need to use CharacterController with appropriate methods, or apply a force to the object to offset. And I would consider the speed remembering the last position (lastPosition) in the FixedUpdate method before calculating physics, then comparing the position in Update between the current and lastPosition , and if the length of the movement is small, it would simply stop the character.

  • you're right. CharacterController suits me. I try to solve simple problems with simple methods. Using CharacterController will not affect performance? - Georgich
  • Perform tests, most of them work smartly) - KingPeas