- Home /
Player movement
I want to make a game where the player moves all the time in one direction but when you click/tap it switches the direction (2D game),I want to make a game where the player moves all the time in one direction but when you click/tap it switches the direction
Answer by rob11 · Oct 24, 2019 at 05:22 PM
Have the player move in a direction and then when you click, you invert that direction.
example :
void Update(){
transform.position.x += 0.01f * moveSpeed * Time.deltaTime; //will move every frame in a direction
if (click)
{
moveSpeed = -moveSpeed; //invert direction
}
}
You certainly will have to tune this but the logic remains the same.
I have a problem "The name 'Click' does not exist in current contecst" What do I do
I wrote click where you would enter any piece of code you want to detect if the player has clicked. Like Input.Get$$anonymous$$ouseButtonDown(0)
Your answer
Follow this Question
Related Questions
How can I move the character like 2D games? 1 Answer
Player movement boudaries in 2D 1 Answer
Player movement for iOS? 1 Answer
2.5D Isometric Move Character and Facing towards mouse 0 Answers