enemy bullets shoot at player, but not track?

pjnolenpjnolen Member Posts: 152
edited November -1 in Working with GS (Mac)
I've been playing with the various move/change velocity behaviors but i can't find a setup that allows my badguys to shoot at the goodguy and just have the bullet move straight to the goodguy's location AT the time of the shooting. If I constrain it to his location, it just tries to follow him instead of moving straight off the screen.
I've tried 'move' 'move to' 'change velocity' and 'accelerate'.
How would I do this?

Comments

  • svnsvn Member Posts: 445
    Um, try using vectorToAngle behaviors. Treat it like you would a mouse targeting system.
  • pjnolenpjnolen Member Posts: 152
    excellent idea. I found this post http://gamesalad.com/forums/topic.php?id=8090
    And tried to follow the instructions. I do have attributes constraining the players x and y loc.

    I tried the vectortoAngle with Accelerate Toward. Result was when bullet spawned, game froze.
    With Accelerate, Move, Change Velocity, result was bullet went upwards, even if player was at the bottom.

    What I'm not sure of is this line "vectorToAngle(Actor1.X - Actor2.X, Actor1.Y - Actor2.Y)".

    am I supossed to put all that information into 1 E input? like under the Behavior Move? Or under a Behavior that has 2 E's for an x and y location, like Move To?

    I ask because I've tried both options and neither of them produce the result i'm looking for.
  • pjnolenpjnolen Member Posts: 152
    Ok, I found out if I key in the coordinates in the opposite of that vectorToAngle format, (2.x-1.x,2.y-1.y), the bullet will still TRACK the target. That is by using the Move command. I need it to move towards the player's location 'at the time of firing' and NOT continuously track the player.

    Ideas?
  • BBEnkBBEnk Member Posts: 1,764
    You said you have "Attributes already set up to track good So now.
    Use "Rotate too Position" which will be your target position then set speed 600 uncheck "run to completion" and check "stop on destination"
    Use a "Timer" set at "after 0.25" then a "Move" Rule will send projectile toward target.
    This is how I did it Hope This Helps.
  • pjnolenpjnolen Member Posts: 152
    Ok, I did this. The bullet spawns, then tracks the player, then after .25 seconds moves toward the player at the set speed. If the player moves their ship, the bullet still tracks them like a homing missile, which is great if it was a missile lol.

    But it's still tracking the player :(
  • BBEnkBBEnk Member Posts: 1,764
    did you uncheck run to completion and check stop on destination and the move only has a set speed no direction
  • pjnolenpjnolen Member Posts: 152
    Uncheck run to completion, and stops on destination. Affirmative.

    In the 'Move' behavior i have direction-0, relative to actor, move type additive, speed 300

    When it starts to move, it moves at direction -0 which in degrees is straight to the right.

    so even if my player is on the left side of the screen, and badguy on the right, the bullet will turn in place to face the player, then shoot out of the badguy in the opposite direction, then slowly turn at an angle and eventually come back and hit the player.

    Maybe I'm not understanding when you say 'no direction'. The field to type into is a 360 degree range of motion measured with a numerical value. How do I tell it 'no direction', or 'straight ahead the direction you happen to be facing'?
  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
    easier way is to have two attributes on you bullet, enemyX and enemyY. when you spawn the bullet, change the values to the enemies x and y position, and then move to that position. that will keep it moving to a static location based on the enemy position when fired
  • mattyr64mattyr64 Member Posts: 82
    yeh, i was just about to say, create 2 separate attributes that you can pass in player location (x,y) and only have it update the co-ordinates at the moment from when the enemy actually fires.

    this way the current player position can move, without effecting the position that the bullet is firing to.

    oh and for this i'd just use 'move to'
  • pjnolenpjnolen Member Posts: 152
    That sorta works!

    but one problem. The bullet moves to the players position that it recorded and stopped, but using the Accelerate Toward instead of Move To allows it to keep going.

    but one problem. The bullet gets to the edge of the screen and starts moving back towards the badguy that fired it, so it goes from a missile to a boomerang lol

    the only movement behaviors that have both coordinates are move to and accelerate toward and one stops the bullet the other has it return from whence it came :(
  • pjnolenpjnolen Member Posts: 152
    wait, on second thought, i think the Accelerate Towards is causing it to return because after the bullet passes the location specified in the two attributes, it continues trying to reach that location. So it will pass it, slow down, then reverse back towards it, then repeat that process indefinately(I said it moved back to the actor that fired it, because I had a rule to destroy it after 3 seconds, which is how long it took to pass it then return and pass it again and get near the original shooter then be destroyed. If I remove that rule, the bullet bounces back and fourth over the location specified by those two attributes.

    Any more ideas?
  • mattyr64mattyr64 Member Posts: 82
    maybe add a lifetime for the bullets, so they are only 'alive' for a second or whatever is suitable. when lifetime is up, destroy it.
  • mattyr64mattyr64 Member Posts: 82
    or on reaching the location destroy it
  • pjnolenpjnolen Member Posts: 152
    Well even if I set the timer to 2 seconds then destroy, depending on the angle the bullet comes back on the screen in time. I have walls around the scene so i have it destroy when it hits one of the walls, so far that seems to be working.
  • pjnolenpjnolen Member Posts: 152
    Ok, no that doesn't work either. If the badguy's location is the top corner of the screen, and the player is in the center of the screen or closer then when the bullet misses the player it doesn't make it to the other side of the screen before it turns around and heads back to that specified location.

    I can't destroy it when it reaches its destination because that wouldn't make sense if someone shot a bullet at the player and the player moved the bullet reached where he was and just disappeared, it has to keep going.

    I can't believe we can't just have a bullet move across the screen where the player was and just keep going. Every space shooter ever made has this lol.

    There has got to be a way. :(
  • pjnolenpjnolen Member Posts: 152
    maybe...if I add an amount to the calculated location of the player. like game.playerx+something, in a way that will move the location off the screen?

    There has got to be a way to just tell an actor to 'move forward', which ever direction it's facing.
  • BBEnkBBEnk Member Posts: 1,764
    create a constrain attribute for player's X,Y so you can get player's position.

    use "Rotate to position" put in the X,Y position blocks Put your "game.yourtrackingattribute and game.yourtrackingattribute attributes's "aka what ever you named them target x and target y is what I call mine. speed 600 is what I used. "relative to SCENE"
    "run to completion is unchecked", "stops on destination is checked".

    I used a Timer Rule set for after 0.25 checked run to completion" with a Move Rule speed 300 "Relative to Actor", Direction 0 "move type stacked"

    This worked perfect for my game not saying there is not a easier way but worked for me.
  • pjnolenpjnolen Member Posts: 152
    BBEnk said:
    create a constrain attribute for player's X,Y so you can get player's position.

    use "Rotate to position" put in the X,Y position blocks Put your "game.yourtrackingattribute and game.yourtrackingattribute attributes's "aka what ever you named them target x and target y is what I call mine. speed 600 is what I used. "relative to SCENE"
    "run to completion is unchecked", "stops on destination is checked".

    I used a Timer Rule set for after 0.25 checked run to completion" with a Move Rule speed 300 "Relative to Actor", Direction 0 "move type stacked"

    This worked perfect for my game not saying there is not a easier way but worked for me.

    ok, did all this exactly to the letter.

    and it works perfectly....wonder what part i missed the first time. I had to have missed something. BBEnk, thanks man, you just saved my sanity lol.
  • BBEnkBBEnk Member Posts: 1,764
    lol, your welcome.
  • tenrdrmertenrdrmer Member, Sous Chef, Senior Sous-Chef Posts: 9,934
    I know you got this working. But A really Easy way to accomplish this is have 2 real actor level attributes called target.X and target.Y and then your Player location attributes at the Game attribute Level Player.X and Player.Y

    in Your bullet actor. At the Very Top you need to change attbibute behaviors

    -Change attribute self.target.X to game.Player.X
    -Change attribute self.target.Y to game.Player.Y

    then if you are using vector to angle to determine your move the expression would look like this
    VectorToAngle(self.Position.X-self.target.X,self.Position.Y-self.target.Y)

    If you using say move to and need a position instead of angle you just have to use self.target.X and self.target.Y as the positions.

    The issue you are having is you are using a game attribute that is constrained to a value that is always changing meaning if the player moves then the values change and the direction of the move updates. Which is great if you are firing a heat seeking missile. But not so much for a bullet.

    Good Luck
Sign In or Register to comment.