Calculating the angle an item is hit at....

Get help using Construct 2

Post » Sat Nov 10, 2012 9:39 pm

Not sure if Construct 2 has a built-in method for this, or if there's an easy mathematical approach... if an item is rotated and it's hit by another object, how can I calculate which part of the object is hit? I know I can work out the angle between the two objects, but if the main object (i.e my player ship) is rotated, how can I tell which part is hit (e.g the left wing, the right wing, the cockpit etc)?
B
25
S
5
G
3
Posts: 446
Reputation: 5,633

Post » Tue Nov 27, 2012 4:25 am

I too would like to know this. This could be very useful for a fighting game where, depending on the attack, a player would be flung in different directions. Maybe something like an equation to calculate a perpendicular angle using the line between two collision points?
B
32
S
4
Posts: 405
Reputation: 3,219

Post » Tue Nov 27, 2012 4:50 am

Farflamex : Have you considered using multiple Image Points instead ? That way you could say > if Item A hits Image Point LeftWing then ....

Bscarl88 : Is this useful ?emoaeden2012-11-27 04:51:01
Using R238 for all examples
B
60
S
17
G
6
Posts: 363
Reputation: 9,125

Post » Tue Nov 27, 2012 5:10 am

Is that the calculation to produce a perpendicular line? Im not very good with my funtions yet haha.
B
32
S
4
Posts: 405
Reputation: 3,219

Post » Tue Nov 27, 2012 5:29 am

That calculation states what the angle of movement is from the centre of the screen. (just made it 480x480)

So if you move to the right it will be 0, move the the top right, it should be -45, bottom right should be 45.
Using R238 for all examples
B
60
S
17
G
6
Posts: 363
Reputation: 9,125

Post » Tue Nov 27, 2012 6:24 pm

I think I'm right in saying that you can calculate it by the collision angle minus your facing angle. I think that works. If the collision hits you at 90 degrees (from below) and you're facing 180 degrees (left), then the hit came at 90 - 180 = -90 (converts to 270), which is your left, which is correct.

If the collision came from above (270 degrees) and you were facing left (180), then the angle would be 270 - 180 = 90, which is your right.

That works for my case at least, hope it helps :)
B
25
S
5
G
3
Posts: 446
Reputation: 5,633


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 2 guests