Enemies begin attacking when hero is close
A_Constantin
EnglandMember Posts: 79
How would I make a system in which an enemy actor detects that the hero is in a certain range, it begins attacking the hero?
Comments
Use magnitude to detect the distance between actors, the rule for the enemy would basically be if the magnitude between 'me' and the hero is less than X then trigger the attack rules.
@Socks I'm not very sure what magnitude is... lol
i found this tutorial from @jamie_c very useful for this problem. https://youtube.com/watch?v=Yn9B4vvnR5A&index=9&list=PL3EyGmfc73E0zt1ocAyFvXwIDID0jnD-O
It's a maths function that detects the distance between two actors it looks like this:
magnitude (self.x-hero.x, self.y-hero.y)
This will calculate the distance between 'self' and the hero.
So . . .
Rule: (numeric expression) If magnitude (self.x-hero.x, self.y-hero.y) < 200 then . . . . attack rules.
@Socks thanks very much and I'll also take a look at the link, @deej011
I've made you a quick demo, use the arrow keys to try and get across the screen without being caught by the enemies.
@Socks Was not asking for that much of you but thanks so much!