Run away, he's unstoppable!?

For questions about using Classic.

Post » Tue Jan 05, 2010 2:41 am

Within my enemy AI group I want to have an event that tests if the enemy's health is below a certain level, then it makes them flee.

But that's just the problem, see, I could simply test the player's x and y coordinates relative to the enemy and then have the enemy move in the proper direction but that's 4-6 different events, I was hoping there is a more efficient way of doing such a thing, with perhaps only [color=#BF0000:11o2tdu8]ONE[/color:11o2tdu8] event.

So the idea is, with an RTS movement event "move to position", what, my good sir might I enter in the X and Y coordinates boxes to make the enemy move [color=#BF0000:11o2tdu8]AWAY[/color:11o2tdu8] from the player?
B
2
G
3
Posts: 25
Reputation: 900

Post » Tue Jan 05, 2010 2:54 am

This formula should do essentially what you're looking for:

X: enemy.x + [color=#FF0000:3sqjxr7i]cos( [/color:3sqjxr7i][color=#0000BF:3sqjxr7i]angle([/color:3sqjxr7i]player.x, player.y, enemy.x, enemy.y[color=#0000BF:3sqjxr7i])[/color:3sqjxr7i] [color=#FF0000:3sqjxr7i])[/color:3sqjxr7i] * 100
Y: enemy.y + [color=#FF0000:3sqjxr7i]sin( [/color:3sqjxr7i][color=#0000BF:3sqjxr7i]angle([/color:3sqjxr7i]player.x, player.y, enemy.x, enemy.y[color=#0000BF:3sqjxr7i])[/color:3sqjxr7i] [color=#FF0000:3sqjxr7i])[/color:3sqjxr7i] * 100

This will have the enemy move in the most "away" direction as possible from the player.
Moderator
B
99
S
37
G
19
Posts: 1,584
Reputation: 17,842

Post » Tue Jan 05, 2010 3:20 am

That was exactly what I wanted, thankyouz!
B
2
G
3
Posts: 25
Reputation: 900


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 2 guests