Smoothing out how fast a gameobject moves?
I'm creating an endless runner kind of game, except you skate down a street. I'm going to have the player switch lanes the same way you would in Subway Surfers, by swiping left/right and jumping/diving by swiping up/down. I would like to smoothen out how fast the player switches and jumps. Right now here is my code: public class MoveRight : MonoBehaviour {
void Update ()
{
transform.Translate(0f, 0f, .25f);
if (Input.GetKeyDown (KeyCode.F))
{
transform.Translate (-2f, 0f, 0.25f);
}
if (Input.GetKeyDown (KeyCode.H))
{
transform.Translate (2f, 0f, 0.25f);
}
if (Input.GetKeyDown (KeyCode.G))
{
transform.Translate (0f, 3f, 0.5f);
}
}
}
I've tried multiplying each by Time.deltaTime and it goes too slow while Time.maximumDeltaTime isn't smooth. How would I go about smoothing this out? I also don't want it to take 3 seconds to switch lanes or jump, just smooth it out while keeping it speedish. I'm going to add a feature so when the player switches lanes their character will lean that way so I don't want it to be super fast switching but smooth and fast enough to make it realistic.
Also, in the future I might switch to them tilting the device like in Temple Run, and then just multiplying how are they tit to make the character leaning proportional to that?
The only thing I need help on is smoothing out when they switch lanes.
You could have a global speed variable, rather than hard coding the speed. From what I think you mean by "smoothing" try using linear interpolation over Time.deltaTime * speed,