I'm working on an platformer enemy that will choose to either go to player.x+50 or player.x-50 and then attack the player.
I want him to choose the nearest point. Is there an expression that allows me to do that?
If the enemy is to the right of the player, then it's closer to player.x + 50, to the left it's closer to player.X - 50, so the following -- which uses a conditional expression -- gets you the desired X coordinate:
enemy.X < player.X ? (player.X - 50) : (player.X + 50)[/code:3ly2dk1z]
Develop games in your browser. Powerful, performant & highly capable.
Wonderful! Thank you very much for the information! I'll get to coding/testing