nearest point

Get help using Construct 2

Post » Sat Sep 19, 2015 12:53 am

Hello again!

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?
B
71
S
41
G
24
Posts: 356
Reputation: 18,464

Post » Sat Sep 19, 2015 1:01 am

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:

Code: Select all
enemy.X < player.X ? (player.X - 50) : (player.X + 50)
Moderator
B
113
S
41
G
20
Posts: 1,586
Reputation: 19,126

Post » Sat Sep 19, 2015 1:18 am

Wonderful! Thank you very much for the information! I'll get to coding/testing :)
B
71
S
41
G
24
Posts: 356
Reputation: 18,464


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 10 guests