How do I calculate sides of an object?

0 favourites
  • 3 posts
From the Asset Store
Build your own spaceship for your side scroller space shooter games with various components.
  • 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?

  • Try Construct 3

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

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

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