Quantcast
Channel: Answers by "ransomink"
Viewing all articles
Browse latest Browse all 80

Answer by ransomink

$
0
0
No problem, you'll want to check the player's previous position against their current position. If the distance is the same or minimal (using a tolerance), they're not moving. When the player moves, set their position to lastPos. Then, check the difference of the x value between the lastPos and curPos variables... - Here is a sample of how it could be done: public bool moving; public float tolerance; public Vector2 prevPos; public Vector2 curPos; private Transform t; void Awake() { t = transform; } void Update() { // Move the game object however you set it up // This line is where you set the velocity to move your game object. // Moving? (along the horizontal axis) if ( t.position.x - tolerance > prevPos.x ) { // Set last position prevPos = t.position; } else { // We're not moving moving = false; } } - Alternatively, you can get the distance between both positions but since your game is an endless runner, you only need to check against one axis...

Viewing all articles
Browse latest Browse all 80

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>