x


Calculating a projectiles angle required to hit object.

I'm trying to use the formula alt text

from http://en.wikipedia.org/wiki/Trajectory_of_a_projectile to work out the angle required to launch a projectile a known distance with the launch height not being the same as the targets. I'm not sure if I've coded it right because the result seems to be incorrect. Any help is appreciated.

var distance : float; //target distance
var height : float // launch height
var reqAngle : float;

 function Start()
 {
    RequiredAngle(distance, height);
 }
function RequiredAngle(x,y)
{
    reqAngle = Mathf.Atan(Mathf.Pow(velocity,2)
        +Mathf.Sqrt((Mathf.Pow(velocity,4)
        -(gravity*(Mathf.Pow(gravity*x,2)
        +Mathf.Pow(2*y*velocity,2)
        /gravity*x)))));    
}
more ▼

asked Jan 30 '11 at 08:51 AM

efreet gravatar image

efreet
47 5 5 7

Dec 02 '11 at 02:48 AM Karsnen
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first
more ▼

answered Dec 02 '11 at 03:27 AM

Karsnen gravatar image

Karsnen
736 26 45 53

(comments are locked)
10|3000 characters needed characters left

The inner-most bracket expression says to take g and multiply it by x-squared and then add two times y times v-squared. In your code you are squaring gravity times x and two times y times v.

more ▼

answered Jan 30 '11 at 01:13 PM

Graham Dunnett gravatar image

Graham Dunnett ♦♦
11.7k 11 20 64

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1865
x286
x251
x11

asked: Jan 30 '11 at 08:51 AM

Seen: 2076 times

Last Updated: Dec 02 '11 at 03:27 AM