Asteroids / Top down shooter hit location?

Get help using Construct 2

Post » Wed Feb 05, 2014 1:37 pm

Hi all,

I have a player ship with 4 armour locations, front, rear, left, right.

I'm trying to determine the angle a bullet hits the player ship so to determine hit location (like which armour takes damage). 0 is front, 90 is right side, 180 is rear, 270 is left.

The world angles are zero to the left, then clockwise around.

I know the player's angle of rotation. I know the world angle the bullet comes from with respect to the player.

I just don't know how to translate that to a hit location. Please see the image below:

B
31
S
7
G
1
Posts: 80
Reputation: 2,550

Post » Wed Feb 05, 2014 1:57 pm

If I understand right, in the image :
Angle(World,Player) = 45
Angle(World,Enemy) = 270
(By the way, usually, angles are handled counter-clockwise)

What you want is Angle(Enemy,Player). Let's decompose angles then :

Angle(Enemy,Player)
= Angle(Enemy,World) + Angle(World,Player)
= - Angle(World,Enemy) + Angle(World,Player)

In the schema's case :
Angle(Enemy,Player) = - 270 + 45 = -225 = 135, seems about right.

Then, hit location is just a switch case.
If the angle(Enemy,Player) is between -45 and +45, it's the front side.
If the angle(Enemy,Player) is between 45 and 135, it's the right side.
If the angle(Enemy,Player) is between -45 and -135, it's the left side.
If the angle(Enemy,Player) is between 135 and 225, it's the back side.
B
17
S
8
G
4
Posts: 473
Reputation: 6,211

Post » Wed Feb 05, 2014 2:20 pm

Perhaps another approach:

add 4 origin points point to your player, each side one.

add 4 invisible collision sprites, each one pinned on one of the origin locations.

Determine hits by means of detecting collisions on the given sprites.


edit: I suggested this, because when you use the angle approach and the players rotate, the results will be off.lennaert2014-02-05 14:34:32
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572

Post » Wed Feb 05, 2014 4:43 pm

OK I think I came up with something (with a lot of help) that works and takes the player's rotation into account.



B
31
S
7
G
1
Posts: 80
Reputation: 2,550


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 8 guests