Best way to Have a Rotate to angle and then Shoot

PortymanPortyman Member, PRO Posts: 409
edited November -1 in Working with GS (Mac)
I want to be able to touch the screen and have a actor rotate to that position and then fire. I have the rotate, but how should i do the fire? I have run to completion checked, but the missile fires to early. Help would be appreciated.

Thanks

Comments

  • scitunesscitunes Member, Sous Chef Posts: 4,047
    If you use vectorToAngle to get the angle between the shooter and the touch X and Y you can use rotate to angle (as opposed to rotate to position).

    What I would do is have an angle attribute called self.shootAngle and a boolean called self.shoot

    Then have a rule that says

    when touch is pressed
    change self.shoot to true
    change self.shootAngle to VectorToAngle(self.position.X-touch1.X, self.positionY-touch1Y)
    Then rotate to angle self.shootangle

    rule- when self.shoot is true AND
    when self.rotation = self.shootAngle
    Spawn bullet (spawn angle of zero relative to actor)
    change self.shoot to false

    should work
  • PortymanPortyman Member, PRO Posts: 409
    That worked perfectly. A side note in case someone else is reading.

    I nested the 2nd rule to mAke it more efficient. Small change but I have gotten far into projects and needed the extra fps

    Ie

    Rule

    When shoot is true

    Rule

    When self rotation is = to shoot angle

    Thanks a bunch. This really did the job
Sign In or Register to comment.