Search code examples
c#unity-game-enginegame-physicsrigid-bodies

Unity: How can I find out what angle I need to shoot from for a physics projectile to land in a certain spot


I need a little help with the math for physics.

Imagine you are shooting bullets from a cannon and depending on angle of the cannon bullet lands at different spots. The force applied to bullet is Unity impulse type.

What would be the best way to calculate what angle I must shoot from to make sure bullet always lands at specific point on the ground?

Vector3 dir = Quaternion.AngleAxis(angle, Vector3.forward) * Vector3.up; _Bullet.AddForce(dir * BulletSpeed, ForceMode.Impulse);

thanks in advance


Solution

  • The equations are

    equations of ballistic flight

    You can also try Projectile Shooter from Wolfram Alpha.