- Home /
Cancel Input if the direction has a wall in the way
When my player roams the scene, I don't want him continuously running into the wall, so how can i stop accepting input if a wall is in the direction of said input?
My goal is to prevent the player animations from continuously looping if he can't go anywhere.
I think N3K has what I'm looking for in their MotorHelper script (https://gitlab.com/N3K/movement-controller/blob/master/Assets/Scripts/Motor/MotorHelper.cs) with KillVector, but they are using CharacterController's properties to detect the "tokill" vector and I'm using Rigidbody.
Answer by hosseinmatrix · Mar 11, 2018 at 10:58 PM
Cast a ray in your character forward direction, and set a bool variable to keep whether you have a wall in your face or not. then set your forward speed to zero. also it can be used in any other direction. set your animator parameters like (idle, walking, running) using character speed. so when you have a wall in your face, your speed set to zero and your running animation translate to idle.
Your answer
Follow this Question
Related Questions
Quarternion.LookRotation is only rotating my game object on one axis 1 Answer
Simple AddForce Scirpt help 1 Answer
3rd person carrying objects,3rd person picking up objects 0 Answers
Can't use Rigidbody.AddForce to RaycastHit.point 1 Answer
How to rotate an object 360 degrees around a sphere with collisions? 0 Answers