- Home /
How to calculate projectile range
Please check Accepted answer where you can find solution!
@$$anonymous$$97 could you please specify what you mean by it doesn,t work? You get an error, you dont get the correct range or you dont know how to write the formula in C#?
@C_R_E_A_T_R_O_R I wrote that in C#, but range is not calculated correctly. I used rigidbody.velocity to find v, i divided by 9.81 (gravity acceleration) but it is not working
@$$anonymous$$97 What about the angle? And also how do you launch your projectile? With RigidBody.AddForce2D?
Answer by K97 · Jul 09, 2018 at 04:59 PM
I found solution, but i am not going to delete this post, because maybe someone in future will need this. If you want answer, check this link. A member of Unity Technologies gave perfect answer.
This YouTube link shows how script works: https://www.youtube.com/watch?v=3B5NV4bAkoE
This is a link to script: https://forum.unity.com/threads/throw-an-object-along-a-parabola.158855/#post-1087673
Answer by YBtheS · Jul 09, 2018 at 01:54 AM
Try using the formula described here. @Clydeicus wrote "2 * cos(angle) * V * sqrt(2 * sin(angle) * V / 9.81) = range of projectile and V is the initial velocity of your projectile". This assumes that acceleration due to gravity in your project is 9.81m/s^2 (which it is by default). You can just change that number to whatever you have gravity acceleration set to.
@YBtheS I am getting an error like this: transform.position assign attempt for 'mushroom2(Clone)' is not valid. Input position is { NaN, -3.650000, 0.000000 }. I don't know what the error is, but I'll try to debug it. If you like, please check code in question (I just updated it). Thanks for response.
{NaN => Not a Number. Your calculation returns something that is not a number.
Your answer
Follow this Question
Related Questions
C# Projectile Ricochet After Collision2d 1 Answer
How to get the position that is closest to a target within a given radius 0 Answers
Object instantiates on top of the previous object 2 Answers
Checking to see if a position is occupied by a GameObject 2 Answers
Boomerang projectile doesn't return to player if the player has moved 1 Answer