Shooting enemies

Ruslan21Ruslan21 Member Posts: 228
edited November -1 in Working with GS (Mac)
Hello there. Im new to this and would like some help here. Please help.

I have a level that size of 320 by 5000

So i have my actor a to always move up, Now i have enemies randomly on the screen, but i need my enemies to shoot may player AS SOON AS player seen by enemies. Is there a may to do this?
Thanks

Comments

  • chosenonestudioschosenonestudios Member Posts: 1,714
    I'm not totally sure, but what I would try to do is, make it so when your player is on the same y value as your enemies, make them "shoot".... so just use game.position.y of your main character or whatever it is good luck! Oh and you'll probably have to create an attribute that holds your main characters y value
  • Ruslan21Ruslan21 Member Posts: 228
    Thanks for the help but i dont know how to do this. Can you explain step by step pls
    thanks
  • firemaplegamesfiremaplegames Member Posts: 3,211
    You need to keep track of the Main Player's X and Y values.

    Create two global game attributes (real) called PlayerX and PlayerY.

    In the main player actor, constrain these two global game attributes to self.Position.X and self.Position.Y, like this:

    Constrain Attribute
    game.PlayerX To: self.Position.X

    Constrain Attribute
    game.PlayerY To: self.Position.Y

    Now the enemies can keep track of where the Main Player is by using the magnitude function. They can react if the Main Player is, say, 200 pixels away from them. Like this:

    In the Enemy Actor, create a real attribute called MyDistanceFromPlayer.
    Constrain the Attribute like this:

    Constrain Attribute
    self.MyDistanceFromPlayer To: magnitude(abs(game.PlayerX-self.Position.X),abs(game.PlayerY-self.Position.Y))

    Then create a Rule:

    Rule
    When self.MyDistanceFromPlayer < 200
    [Attack the Player]

    Hope this helps!
    Joe
  • Ruslan21Ruslan21 Member Posts: 228
    @firemaplegames

    Thank you very very much
Sign In or Register to comment.