I am making a game where the character is running and things are coming at him. The character runs forward on his own but i want the player to be able to make the character move into the separate lanes. There are three lanes and I want to know how to make it so i click a button and he moves there, but with like a half second moving time. For example if you wanted to go to lane on the left you could click 1, for the lane in the middle 2, and for the lane on the right 3. Thanks in advance.
//variables to be defined
public float Lane1Pos = 0;
public float Lane2Pos = 5;
public float Lane3Pos = 10;
public float CurrentPos = 0;
Void Update()
{
if(input.GetKeyDown(Keycode.D))
{
if(CurrentPos == 0)
{
transform.position = new Vector3(Lane2Pos, 0, 0);
CurrentPos = 1;
}
if(input.GetKeyDown(Keycode.D))
{
if(CurrentPos == 1)
{
transform.position = new Vector3(Lane3Pos, 0, 0);
CurrentPos = 2;
}
if(input.GetKeyDown(Keycode.D))
{
if(CurrentPos == 2)
{
CurrentPos = 0;
transform.position = new Vector3(Lane1Pos, 0, 0);
}
}
}
This is something along the lines of what you would want too do i think. This isnt tested. I have no idea if it will work as im not near my pc.