Following actor & matching x location to fire

ZeroRavenZeroRaven Member Posts: 33
edited December 2013 in Working with GS (Mac)
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.

Answers

  • -Timo--Timo- Member Posts: 2,313
    first,
    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
  • ZeroRavenZeroRaven Member Posts: 33
    @timolapre1998

    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.
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited December 2013

    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

  • -Timo--Timo- Member Posts: 2,313
    move to X=game.playerX y=self.position.Y
    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
  • ZeroRavenZeroRaven Member Posts: 33
    Ok so I'm using a "move to" code to move towards x(game.playerpositionx) y(self.positiony) relative to scene. I've tried both run to completion and without RtC. Both times the enemy shot to the left of the screen and stuck there, not moving.
    I tried as relative to actor, and the enemy flew backwards at a 45 degree angle and dissapeared off screen.
Sign In or Register to comment.