Search Unity

Projectile Range

Discussion in 'Scripting' started by Gamer_, Mar 2, 2010.

  1. Gamer_

    Gamer_

    Joined:
    Dec 4, 2009
    Posts:
    74
    Hi to all guys i am not good in physics and trigonometric I tried to do a projectile system.My launch point is higher than target point.I know the velocity v, target_distance d, gravity g,Launch_height_y y0.I added an attachment that shows the equation.I tried my own but not solved the equation.Please some one help me

    d = 30,v = 22 , g = 9.8 ,y0 = 2

    I wants to find the theta(angle)
     
  2. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    There is some discussion of projectile launching in this thread.
     
  3. antrock101

    antrock101

    Joined:
    Dec 19, 2009
    Posts:
    88
  4. Mirage

    Mirage

    Joined:
    Jan 13, 2010
    Posts:
    230
    That is going to be a gigantic mess, especialy if you have more than one projectile being launched. Unity has not proven to be very efficient at upper level math (which is what that would turn out to be). I would reccomend using a rigidbody on the projectile and let Unity's built in physics solve whatever needs to be done. Maby some dynamic rigidbody.drag altering, but that would be about it.
     
  5. Kragh

    Kragh

    Joined:
    Jan 22, 2008
    Posts:
    657
    It's pretty hard to predict where a projectile will hit, if no calculations are done beforehand. I guess if you would make an AI shoot back, you would need to at leas know what goes on behind the physX engine, so the enemy can hit you at all :)
     
  6. antrock101

    antrock101

    Joined:
    Dec 19, 2009
    Posts:
    88
    i'm not great with maths but i thought you could find the angle by knowing the distance and initial velocity?
     
  7. ivkoni

    ivkoni

    Joined:
    Jan 26, 2009
    Posts:
    978
    sure you can:
    http://en.wikipedia.org/wiki/Trajectory_of_a_projectile#Angle_of_reach


    How do you know this?

    You only have one arctan and one square root + a few multiplications to make this calculation.

    You can also always write your own solver to solve the 2 equations but better use the formula. The solver will be slower.


    [/code]