2D Enemy Following with Lerp problem
I am making a top-down 2D rogue-like and am working on the Enemy AI at the moment. I am using Lerp to get the enemy to follow the player and am having a problem. If the player pushes the Enemy, the Enemy will follow the player at the distance that they were pushed.
For example, if the Player pushes the Enemy 2 units to the right, from that point on, the Enemy will follow the Player with a space of 2 units to the right between them.
My code for following is as follows:
transform.position = Vector3.Lerp(transform.position,target.position,speed*timer); if(transform.position == target.position){ timer = Mathf.Clamp(timer - Time.deltaTime,0.0f,1.0f/speed); } else{ timer = Mathf.Clamp(timer + Time.deltaTime,0.0f,1.0f/speed); }
I appreciate any help with this and please let me know if I didn't explain my problem sufficiently. Thanks.
Your answer
Follow this Question
Related Questions
Smooth Rotation Quaternion Lerp? 1 Answer
How to make soccer ball spin according to its velocity in 2D top down game 0 Answers
Random Generation 1 Answer
2D Enemy Ai 0 Answers
2D Movement Controls Like a Dying Fly 0 Answers