Applying fake drag/resistance to an object
I have a script that follows a spline with a speed.
I have another script that controls the speed by calculating the Vector3.Dot(transform.forward, Vector3.up)
this gives a negative or a positive value)
positive -> object's forward vector is point up in world direction)
negative -> object's forward vector is pointing down in world direction
So if i have a negative Dot, that means i need to increase the speed which the object is moving, i do the opposite if the Dot is positive, which means its looking up.)
I am trying to mimic a rollercoaster cart.)
Here is a gif of how its currently moving:)
Works well but there is another issue i see is that the Dot seems to be inconsistent because it always overshoots on the other end and in reality it should barely touch the other end and come back but that's not a big issue right now.)
I need a way to deaccelerate this object over time so eventually it will stop at the center of this curve.)
Any tips?)
By the way the code that im using to fake it's speed is)
float dot = Vector3.Dot(transform.forward, Vector3.up);
float dotAbs = Mathf.Abs(dot);
if(dot < 0)
{
follower.speed += dotAbs * 5 * Time.deltaTime;
}
else if(dot > 0)
{
follower.speed -= dotAbs * 5 * Time.deltaTime;
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612185106im_/https://answers.unity.com/themes/thub/images/avi.jpg)