Enemies begin attacking when hero is close

A_ConstantinA_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

  • SocksSocks London, UK.Member Posts: 12,822

    @A_Constantin said:
    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?

    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.

  • A_ConstantinA_Constantin EnglandMember Posts: 79

    @Socks I'm not very sure what magnitude is... lol

  • deej011deej011 Member Posts: 159
  • SocksSocks London, UK.Member Posts: 12,822
    edited February 2015

    @A_Constantin said:
    Socks I'm not very sure what magnitude is... lol

    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.

  • A_ConstantinA_Constantin EnglandMember Posts: 79

    @Socks thanks very much and I'll also take a look at the link, @deej011

  • SocksSocks London, UK.Member Posts: 12,822

    @A_Constantin said:
    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.

  • A_ConstantinA_Constantin EnglandMember Posts: 79

    @Socks Was not asking for that much of you but thanks so much! ;)

Sign In or Register to comment.