Sooooo I’m making a 2D sidescrolling game and I’m working on some AI units that can lob their shots if I want them to but the physics isn’t working out… I have an aiming script that works great and compensates for the player’s Y position, but when I change the angle of fire to what should be it’s complementary trajectory it overshoots by quite a bit…
How it should work is if you fire anything with gravity and a consistent firing speed at an angle below 45 degrees you should be able to fire at the same point at a higher angle that is the inverse difference from 90 as the first one is from 0…
Example.
Firing angle 1 is 15 degrees, you should also be able to hit the same target with an angle of 75 degrees.
the formula for this is
angle2 = 90 - angle1
Only it doesn’t work in unity.
so here’s how I have it implemented, it gets what the correct firing angles should be, but they overshoot. If I turn off the lob if statement the bullets hit perfectly fine, but on the lower trajectory.
...
if (lob){
if (targetRotation > 0 targetRotation < 45) {
targetRotation = 90 - targetRotation;
}
if (targetRotation > 135 targetRotation < 180) {
targetRotation = 180 - targetRotation + 90;
}
}
transform.eulerAngles = Vector3(0, 0, (targetRotation));
Any Ideas?
I even checked to make sure the rigidbody launcher was instancing the projectiles at the right speeds and everything looked fine with that.