Following actor & matching x location to fire
ZeroRaven
Member Posts: 33
Hey again guys. You always seem to help when I need it so thanks.
Lets see, 2 questions in one.
First, I'm trying to get an "enemy" actor to follow a player actor as it "flies" down the screen.
I've tried the "set game.playerpositionx to self.positionx" change attribute and then having the "enemy" move towards the game attribute positionx. (same set for y), however I dont want it to track player position Y. Though the move towards coding requires both an x & y position.
Tried setting the y coordinate to -1, hoping that it would just read the X Position, but to no avail.
Basically i want the enemy to track the player left and right, but still move down/forward on its own motion.
Second, I want the "enemy" to fire at the player when the player is infront of the "enemy".
So essentially when the player and enemy share the same X coordinate, the enemy actor will spawn the laser blasts.
I've tried using the same setup for tracking left and right, I.E. setting the game attributes to the player position, then having a code in the enemy actor which checks that attribute, so when self.positionx is = to game.playerpositionx it should spawn the lasers, but it doesnt.
Anyone have an idea of how i can utilize the above effects? All i can find is how to track the player x and y position.
Lets see, 2 questions in one.
First, I'm trying to get an "enemy" actor to follow a player actor as it "flies" down the screen.
I've tried the "set game.playerpositionx to self.positionx" change attribute and then having the "enemy" move towards the game attribute positionx. (same set for y), however I dont want it to track player position Y. Though the move towards coding requires both an x & y position.
Tried setting the y coordinate to -1, hoping that it would just read the X Position, but to no avail.
Basically i want the enemy to track the player left and right, but still move down/forward on its own motion.
Second, I want the "enemy" to fire at the player when the player is infront of the "enemy".
So essentially when the player and enemy share the same X coordinate, the enemy actor will spawn the laser blasts.
I've tried using the same setup for tracking left and right, I.E. setting the game attributes to the player position, then having a code in the enemy actor which checks that attribute, so when self.positionx is = to game.playerpositionx it should spawn the lasers, but it doesnt.
Anyone have an idea of how i can utilize the above effects? All i can find is how to track the player x and y position.
Answers
make 2 attributes (lets say we call them playerX and playerY)
in the player constrain self.position.X to game.playerX and constrain self.position.Y to game.playerY
in the enemy use the behavior move to x=game.playerX y=game.playerY speed:whatever you want.
in the enemy if self.position.X = game.playerX
do
spawn laser
inside the laser you place what you want to do with the laser. move down or whatever
hope this helps
✮ FREE templates at GSinvention ✮
✮ Available for hire! support@gsinvention.com ✮
I've done that. Only problem is i don't need to follow the players y position. The enemy is coming from the top of the screen and flying past the player. So all i want to do is track the side to side movement.
And the laser spawn setup you described is exactly what I used. It didn't spawn the lasers for me.
Hi @ZeroRaven Basically what @timolapre1998said, although you don't need the constrain on the playerY, as you mentioned.
Only able to fire when enemy x coordinate matches player x coordinate, and both are moving all round? You'll be waiting a month of Sundays for it to fire… ;-)
Maybe add a wider range, as a suggestion… when self.Position.X > game.player.X-21 and when self.Position.X < game.player.X+21, for instance.
Please make more descriptive thread titles next time, cheers! :-) (I'll change yours now).
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
and if you want it to stop moving when he is shooting then make a self attribute (boolean)
if self.boolean is false do move to X=game.playerX Y=self.positionY
if self.position.x > game.playerX-20 AND if self.position.x < game.playerX+20
change self.boolean to true
after 2 seconds change self.boolean to false
spawn laser
✮ FREE templates at GSinvention ✮
✮ Available for hire! support@gsinvention.com ✮
I tried as relative to actor, and the enemy flew backwards at a 45 degree angle and dissapeared off screen.