Search code examples
mathtrigonometryangleeuler-angles

Finding the angle a projectile hits a rotated circle


I'm trying to find out which side an entity is hit

46-135 - right side

136-225 - back side

226-315 - left side

316-360 and 0-45 - front side

https://i.ibb.co/hKz5n9z/Help.png (Can't post images but this is what i want)

I know the angle the entity is facing and the angle of the projectile when it hits the entity

I've tried things like:

Math.abs(entityRotation - attackRotation) % 360;

Math.abs(180 - entityRotation - attackRotation) % 360; etc.

But I cant seem to find an equation that works for all angles.

If that's not possible I can use two different equations for when one angle is greater than the other.

Thank you :)


Solution

  • If projectile always is directed to the circle center, try the next approach
    (Python code, uses integer division //)
    result here

    print("targdir", " attackdir", "side")
    sides = ["front", "right", "back", "left"]
    for target in range(0, 361, 45):
        for attack in range(0, 361, 45):
            side = ((attack - target + 585) % 360) // 90
            print(target, attack, sides[side])