# How do I calculate sides of an object?

Get help using Construct 2

### » Thu Aug 11, 2016 12:46 am

Gday all,

Such a simple little thing, I thought. That's now been bugging me for a week. So clearly not so simple. Or staring me in the face. I don't know.

My problem:

I'm seeking a way to calculate the 'side' that one object is to relative to another object. The purpose is to calculate which side a target has been hit when another target shoots at it.

To illustrate:

So here, the green object has 'fired' at the red object (the target). It would be a right side hit.

I have had the system working in a few ways. Previously I just used 'within' and '90 degrees' while plugging in the angle between the two objects, and this seemed to work for calculating front and rear hits. But I need to bring in left and right sides as well, and I can't figure out how to do so. Again, I can calculate a static target, but this system also needs to take into account the rotation of the target.

Thoughts?
B
11
S
2
Posts: 13
Reputation: 601

### » Thu Aug 11, 2016 5:22 am

Can't you just use 'within' and '45 degrees' instead?

On impact simply compare the angle of bullet and target, eg:

( Bullet.Angle - Target.Angle ) is within 45 degrees of angle 180 = Front
( Bullet.Angle - Target.Angle ) is within 45 degrees of angle 270 = Left
( Bullet.Angle - Target.Angle ) is within 45 degrees of angle 90 = Right
( Bullet.Angle - Target.Angle ) is within 45 degrees of angle 0 = Rear

You might need to switch your left/right on that, but something similar should work.
The LEVEL GENERATOR TOOLKIT

24 functions dedicated to producing randomly generated terrain for all kinds of games.
B
25
S
7
Posts: 254
Reputation: 2,332

### » Thu Aug 11, 2016 5:45 am

Cheers! My issue was that I didn't even realise there was a base system angle within where I was only using an object's.

I used angle(target.X, target.Y, shooter.X, shooter.Y) instead of ( Bullet.Angle - Target.Angle ) since I wasn't sure how that ended with the value I needed, also simply by adding the target's angle onto the second angle I took into account the rotation of the target.
B
11
S
2
Posts: 13
Reputation: 601