Shooting enemies
Ruslan21
Member Posts: 228
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
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
thanks
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
Thank you very very much