enemy actor shooting within a certain distance

digitalzerodigitalzero Member, BASIC Posts: 639

so im trying to get my enemy actor to shoot my hero actor within a certain distance... i been looking on the forums for about 20 minutes but i give up... in the picture below the hero actor is on the left and the enemy is on the right but i want it to be that distance

Image and video hosting by TinyPic

Comments

  • SRPentSRPent Member, PRO Posts: 10

    I don't really know, but I have an idea:

    I think you can create a giant square or circle (that is invisible) around the hero that when collides with the enemy activates an attribute that tells him (the enemy) to shoot. Or two (one left, other right). (You should first calculate the pixel distance).

    Hope it works. :)

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

    This distance between them is . . .

    abs(enemy - hero)

    . . . so just check to see if this is smaller than a certain value and if it is then get blasting !

  • digitalzerodigitalzero Member, BASIC Posts: 639

    @socks i have no idea how to write that in code lol

  • SocksSocks London, UK.Member Posts: 12,822
    edited September 2014

    @digitalzero said:
    socks i have no idea how to write that in code lol

    Not at my computer right now, so off the top of my head (mistakes included !) it should look something like this . . .

    If abs (enemy.position.X - self.position.X) is smaller than 100 . . .

    The do some stuff !

Sign In or Register to comment.