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

Get help using Construct 2

» Thu Jul 02, 2015 4:35 pm

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.
B
22
S
6
G
2
Posts: 30
Reputation: 1,879

» Thu Jul 02, 2015 11:11 pm

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
B
17
S
7
Posts: 280
Reputation: 2,522

» Thu Jul 02, 2015 11:49 pm

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
B
28
S
17
G
156
Posts: 892
Reputation: 81,252

» Sat Jul 04, 2015 12:21 am

thanks for reply's i will try them now
B
22
S
6
G
2
Posts: 30
Reputation: 1,879

» Sat Jul 04, 2015 5:21 am

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.
Last edited by Drakkith on Sat Jul 04, 2015 5:28 am, edited 1 time in total.
B
8
S
2
Posts: 35
Reputation: 572

» Sat Jul 04, 2015 5:23 am

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.
B
8
S
2
Posts: 35
Reputation: 572

» Sat Jul 04, 2015 7:08 am

@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.
B
28
S
17
G
156
Posts: 892
Reputation: 81,252

» Sat Jul 04, 2015 4:18 pm

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!!
B
22
S
6
G
2
Posts: 30
Reputation: 1,879