How Do You Keep Bullets In a straight Line?

hzappshzapps Member, PRO Posts: 173
edited September 2012 in Working with GS (Mac)
I finally was able to get the moving enemy spawn a bullet and fly towards my actor, but it follows the actor instead of following a straight line until it destroys itself? Does anyone have any thoughts? How about how to keep the enemy actor from rotating away from my actor? I am using PlayerX, PlayerY already, but sometimes the enemy actor will continue rotating away from my actor eventhough it is moving towards it?

Comments

  • RPRP Member Posts: 1,990
    edited September 2012
    It hard to tell what all you have going on in your code without seeing it.

    Tell us what behaviors or/attributes you have associated with those actors.

    If you can upload screens of your settings or a vid of what is occurring, it would help out a big time. Otherwise I would check the cookbook, it should be just as easy as this:
  • mhmmamhmma Member Posts: 5
    i had the same problem with an enemie that should fly in the direction towards the player but not following him ... its a little bit tricky to do that ...

    you need in the bullet actor some attributes

    bullettrigger - boolean - false
    angle1 - real
    angle2 - real

    now do following
    add a rule
    bullettrigger false

    add a change attribute behavior
    insert in first field
    self.angle1
    insert in second field
    atan((game.Playery-self.position.y)/(game.Playerx-self.position.x))+180

    add another change attribute behavior
    insert in first field
    self.angle2
    insert in second field
    atan((game.Playery-self.position.y)/(game.Playerx-self.position.x))

    the first one is if the player is on the left side of the bullet ... the other one if the player is on the right

    now a new rule
    if self.position.X > game.Player.X /// player is on the left
    now insert a move behavior.
    in the direction field insert
    self.angle1

    otherwise

    insert a move behavior
    in the direction field insert
    self.angle2


    i hope that works ... and i explained everything so it makes perfect sense for you :)

  • famekraftsfamekrafts Member, BASIC Posts: 834
    What you have right now is fine, for any homing missiles, there should be a probability of not hitting the player. I give player.x( also y) + random(0, 20) in the accelerate behavior, so it can even miss the player if randomly generated.

    It rotates because, for some reason the player moves and its x and y coordinates changes, so it rotates relative to that to apply the new changes.

Sign In or Register to comment.