- Home /
How to tell the game if the player is not moving
Currently, I am trying to create a 2D runner. The ground in this infinite runner moves to the left, and when it gets off screen, I've written a script to cause it to move back to the far right of the screen. The ground has a collider on it to allow the player to stand on it, but whenever the player stands on this ground, he does not slide to the left with the ground. To solve this problem, I've decided that the best thing to do would be to make the player move to the left at the same speed as the ground. The thing with this is that I want the player to move to the left only when the player is not making any movement inputs.
So, if I want to tell the game, "Only move the player to the left when the player is not making any inputs", how would I do this? If anyone can help, it would be greatly appreciated.
Answer by RecyclingBen · Mar 22, 2017 at 03:31 PM
try something like
bool playerIsMoving
if (Input.anyKeyDown == true)
{
playerIsMoving = false;
}
else
{
playerIsMoving = true;
}
Input.anyKeyDown basically just checks if there is any input being made, like a mouse click or keyboard button click
hope this helped
Thanks! That was a lot cleaner than what I planned to do.
Your answer
![](https://koobas.hobune.stream/wayback/20220612113648im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Best way to set up a city trading system script?,Best way to script city trading system? 1 Answer
creating and using list of prefabs 2 Answers
Can I change animation key frame property in script? 1 Answer
How to Write a Drag and Drop script for Unity 5.3.3? 4 Answers
how to make a detect rotation script for negative rotation too 2 Answers