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

Get help using Construct 2

Post » 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

Post » 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

Post » 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
Image Image
B
25
S
14
G
136
Posts: 876
Reputation: 71,005

Post » 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

Post » 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

Post » Sat Jul 04, 2015 5:23 am

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

Post » 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.
Image Image
B
25
S
14
G
136
Posts: 876
Reputation: 71,005

Post » Sat Jul 04, 2015 4:18 pm

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


Return to How do I....?

Who is online

Users browsing this forum: Artcadev, dop2000, Phacanu, richcoz81, Txchaser and 31 guests