A Physics question. not a unity question.
Calculating a projectile arc
Hi!
I've been struggling with this concept for months now and getting around it by using a more simple aiming system which only works half of the time.
In my game the player fires liquid projectiles (in the form of particles), thus naturally they arc unlike a bullet so I need the aiming system to compensate for this.
The below image illustrates what I'm trying to accomplish:
The white Debug Line is a raycast along the gun's line of sight, and is where the player is aiming.
The 3 arcs show how the weapon would need to angle itself in order to shoot each target that the raycast hits. How would I go about calculating this angle?
Thanks in advance for any help/advice!
Sorry to bump, does anyone have any info about this? I'm at a loss and can't progress :(
The term you are looking for is "$$anonymous$$inematic Equations".
http://www.physicsclassroom.com/class/1D$$anonymous$$in/Lesson-6/$$anonymous$$inematic-Equations
Using these equations you can work out pretty much anything with regard to projectile motion.
Thanks for the pointers, it seems to back up Vallvaka's answer. Are you able to convert Vallvaka's formula below into C# equivalent? I'm finding it difficult to convert into code.
This will help
http://docs.unity3d.com/ScriptReference/$$anonymous$$athf.Asin.html
Do note that Sin based functions in Unity are not super-fast so try not to overuse them, like placing multiple sin functions in Update.
Sorry to have to have closed this question, its just not Unity specific.
Answer by Vallvaka · Oct 16, 2015 at 03:44 AM
The angle of a projectile launch (A) with known parameters initial velocity (V), target distance (x), and gravity (g) is given by
A = 0.5 arcsin(gx / V^2)
For example, the angle for a launch at 50 units per second for a target distance of 200 units with gravity of 9.81 units per second is given by
A = 0.5 arcsin(9.81 * 200 / 100^2) = 25.85 degrees
Sorry about the image not being visible, I'm not sure why that's happening. I can see it when I'm logged in to Answers, but not when I'm logged out so it's a bit odd. This is the image anyway: https://gyazo.com/dd304c712d87da2f23393b74bf380c77
Thankyou for the help, I'm currently trying it implement it in the game, I'll let you know how it goes!
I assume (and hope) you got it working? I can convert it to C# for you if you still need it.
Sorry I didn't get back to you about that, but yes I got it working thanks to you!