- Home /
How to stop player movement slowly fade down?
Hi, sorry i'm Unity beginner and i'm frustated with my current problem. Well i build a running game that player will run until finish line. Near the finish line i want my player stop slowly, i mean the speed movement slowly reduce until its completely stop. how to do that? i have looking for it around this page but i did't get what i need. I try using AddForce but i didn't understand what it is. So, anybody know the simple easy way to do my animation? i move my player with this code example :
if (Input.GetMouseButtonDown(0) && flagStart==0 && counter==0)
{
dir = Vector3.forward; flagStart = 1;
}
and here what should i do to my code :
void OnTriggerEnter(Collider other)
{
if (other.tag == "Player")
{
//code to stop slowly
}
}
Answer by scarletsnake · Apr 20, 2017 at 10:57 AM
I would recommend checking the distance between your player object and the finish line object. Depending on the distance, you can gradually decrease the player character's speed and load different animations.
https://docs.unity3d.com/ScriptReference/Vector3.Distance.html
Check the distance in your Update function, seperate of your triggerenter function. Should do the trick.
Your answer
Follow this Question
Related Questions
Why my character moves left when i press right key ? Controls are upside down? 2 Answers
Code working for tutorial guy but not for me. 1 Answer
How do I make to print something in console on Unity 5.3 1 Answer
How do I make a script that will allow my character to shoot projectiles? 1 Answer
Player colliding with pickable object 0 Answers