syed samoon Posted November 22, 2017 Share Posted November 22, 2017 hi, i need a help. i want to clamp the player movement in certain range. how can i fix it. now i'm using following method the moveleft & moveright is a boolean function. it is working fine. but if the character repul while colliding with collider. then the character move across the given limit. how to clamp it. if (player.moveRight && player.position.x <= 42) { player.position.x += 1; }; if (player.moveLeft && player.position.x >= -42) { player.position.x -= 1; }; Quote Link to comment Share on other sites More sharing options...
Temechon Posted November 22, 2017 Share Posted November 22, 2017 It's hard to understant your code without any live example, but I'll take a shot Can you try something like this ? if (player.moveRight && player.position.x <= 42) { player.position.x += 1; } if (player.moveLeft && player.position.x >= -42) { player.position.x -= 1; } if (player.position.x >= 42) { player.position.x = 42; } if (player.position.x <= -42) { player.position.x = -42; } Quote Link to comment Share on other sites More sharing options...
syed samoon Posted November 22, 2017 Author Share Posted November 22, 2017 thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.