How do u make the enemy shoot to the player's position?

I need help on making the enemy ships shoot at the player ship. As in, if im at coordinates 200x 800y; the enemy will shoot there, but the laser wont follow me like a missile. I've tried many things but.. I can't figure it out
Comments
the bullets keep returning to me no matter what.
I also tried putting a destroy after 3 seconds rule, yet.. it curves right after it passes ship and crashes with back end of ship. =\
sorry for the poor expression in original post.
Like TSB stated, create global attributes named something like "playersX" and "playersy" and on the player ship actor constrain them to the player's self.position x and y attributes.
In the enemy actor add a "spawn actor" behavior (you'll probably want to put this in a timer or other sort of condition to determine how frequent the enemy fires.)
Spawn your enemy's bullet and for the "direction" add this expression from the drop down selections:
vectorToAngle( self.position.X - game.playersX , self.position.Y - game.playersY )-180
In the bullet actor add a move or accelerate speed, plus any other behaviors you want it to have (collide, destroy, etc.)
That should do it!
I must be missing something.
option A)
Have the missile spawn facing the player using vectorToAngle(playerX - spawnX, playerY - spawnY), then just accelerate 0 degrees relative to the actor (the actor in this case is the missile)
option
when the missile first spawns, capture the player's x/y position to some internal self variables using CHANGE attribute. Then accelerate towards that saved position, not the player's position.
My main character has two constraints:
- Constrain game.PlayerX to Self.PositionX
- Constrain game.PlayerY to Self.PositionY
The enemy (pacing via the pacing tutorial on wiki) spawns an actor (we'll call it an Acorn) every 4 seconds. The spawn settings look like this (see screen shot below):
This is what the expression looks like when expanded
The acorn actor (my missile) has the following accelerate logic.
Accelerate > Direction = 0, Relative to actor (self), Acceleration = 100
Any reason why the acorns are flying up into the sky instead of down toward my Player?
Go figure.
I'm definitely doing something wrong. :-(
Cheers
This is me blushing in the presence of my forum friends.
=^_^=
In the expression vectorToAngle(x1-x2, y1-y2)
The direction you want the vector to point is your x1, y1. So if you want the vector to point at your player make x1 and y1 your player's x and y.
The -180 isn't needed at all.
Not sure why.