Hello !
First I hope that I’m in the good place to ask, if not tell me.
I want to create a simple 3D runner.
But I have a problem, about the player movement because I have 3 roads (blue, green, red), and I want that when the player swipe (or click) he move only from one road to another. Consequently this is not free movements.
My initial idea was to assign a number to each road : | -1 | 0 | 1 |. And create some conditions if you’re on 1 and you click on right you will not move because there is no road after the red one.
However it doesn’t work very well.
Picture :
// If we click to left and the position of the player is 0 or 1
if (Input.GetKey("left") && (playerPosition == 0 || playerPosition == 1))
{
// Change direction to left
endPosition = new Vector3(transform.position.x - 1, transform.position.y, transform.position.z);
playerPosition = playerPosition - 1;
Debug.Log("playerPosition Left : " + playerPosition);
}
if (Input.GetKey("right") && (playerPosition == -1 || playerPosition == 0))
{
// Change direction to right
endPosition = new Vector3(transform.position.x + 1, transform.position.y, transform.position.z);
playerPosition = playerPosition + 1;
Debug.Log("playerPosition Right : " + playerPosition);
}
gameObject.transform.position = Vector3.Lerp(direction, endPosition, speed);
}
}
Do you have some advices about how to move this player in relation to the road ?
Thanks and have a good day !