0 Favourites

How do I calculate sides of an object?

  • 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?

  • 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.

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
99 10,152
karshinkoff's avatar
karshinkoff
Unread hot topic
167 14,513
DMT2005's avatar
DMT2005
Unread hot topic
123 14,873
Zebbi's avatar
Zebbi