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
56
S
33
G
23
Posts: 334
Reputation: 16,743

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,106

Post » Sat Sep 19, 2015 1:18 am

Wonderful! Thank you very much for the information! I'll get to coding/testing :)
B
56
S
33
G
23
Posts: 334
Reputation: 16,743


Return to How do I....?

Who is online

Users browsing this forum: Google [Bot], troxx, TwistedSaviour and 1 guest