How do I make an enemy rotate to shoot me side on

  • I'm trying to make a pirate ship type game and i'm having trouble working out how to get the enemy ship to rotate when near me to shoot from the side canons.

    Any offers?

    Thanks.

  • Try setting the side of the ship as the front of the sprite o-o

    Not a good idea, but I would try it. I'll give it some thought, if I figure something out I'll send you a .capx

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • you can try:

    1/on event: pirate_ship rotate X°*dt toward angle player.angle

    2/pirate_ship within 5° of player.angle: action (eg fire)

    If that's work, you can improve the rotation and/or distance

  • thanks for reply's i will try them now

  • Angles are notoriously difficult to work with in my experience, but you can try this:

    Have two instance variables on the pirate ship called "AngleToPlayer" and "DistanceToPlayer"

    Use the following events:

    E.) System: Every Tick: A.) PirateShip: Set Value: AngleToPlayer: "angle(self.x, self.y, player.x, player.y)": A.) Set Value: DistanceToPlayer: "distance(self.x, self.y, player.x, player.y)"

    E.) PirateShip: Compare Instance Variable: DistanceToPlayer is less than X: A.) PirateShip: Rotate Towards Angle: "Self.AngleToPlayer + 90"

    Sub E.) PirateShip: Is Within Angle: 5 degrees of "self.AngleToPlayer + 90": A.) Insert whatever event you need to make the ship fire.

    Note that this makes it so that the ships always fire from one side. You can use the event "is clockwise from angle: self.AngleToPlayer +90" and the inversion of that same event to help you make the pirate ships to turn one way or another. You'll have to change +90 to -90 in some of the earlier events, and +270 if the angle from the pirate ship to the player is less than 90 degrees and you want to fire at the player from the right side of the ship.

  • you can try:

    1/on event: pirate_ship rotate X°*dt toward angle player.angle

    2/pirate_ship within 5° of player.angle: action (eg fire)

    If that's work, you can improve the rotation and/or distance

    I believe the phrase "player.angle" returns the angle that the player's sprite is facing, not the angle from the current sprite to the player.

  • Drakkith

    You're right, with this 2 lines of pseudo code, the ship turns and shoots on only one side. And "player.angle" = player's sprite facing

    With these 2 lines, you can make a basic mechanic in 6 events like this

    This was just a hint, not the complete solution.

  • Thanks for reply's again,

    E.) System: Every Tick: A.) PirateShip: Set Value: AngleToPlayer: "angle(self.x, self.y, player.x, player.y)": A.) Set Value: DistanceToPlayer: "distance(self.x, self.y, player.x, player.y)"

    E.) PirateShip: Compare Instance Variable: DistanceToPlayer is less than X: A.) PirateShip: Rotate Towards Angle: "Self.AngleToPlayer + 90"

    Sub E.) PirateShip: Is Within Angle: 5 degrees of "self.AngleToPlayer + 90": A.) Insert whatever event you need to make the ship fire.

    That worked perfectly

    Thanks Alot!!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)