Question by
LordTickle · Sep 08, 2016 at 12:50 PM ·
javascriptmovement scriptdetection
How to detect if the player is not moving
Hello there! I am having a problem with my javascript code. I want to make a code that detects if the player is moving, and if he does not move for example for 15 seconds, to respawn him at the original starting position.
Comment
Best Answer
Answer by doublemax · Sep 08, 2016 at 01:32 PM
Assuming that you are the one who makes the player move:
Have a float variable, e.g. float last_move_time;
Whenever you move the player, set last_move_time = Time.time;
In your Update() function compare last_move_time to Time.time. If the difference is more than 15 seconds, you have your condition to respawn the player.
(I was using C# class names, i hope the JS names are identical or similar)
It worked, I thought of something like this but I didn't try it. Thanks for the help!