Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function trajectory(start, target, speed, gPrime)
- local dv = target - start;
- -- displacement
- local dx, dy, dz = dv.x, dv.y, dv.z;
- -- horizontal displacement
- local alpha, beta = sqrt(dx*dx+dz*dz), dy;
- local f = 2*speed*speed / g;
- -- discriminant
- local d = f*(f - 2*beta) - 2*alpha*alpha;
- if d<0 then
- print "can't hit target";
- return nil;
- else
- local root = sqrt(d);
- local gamma0, gamma1 = (f+root)/2, (f-root)/2;
- local theta0, theta1 = atan2(gamma0, alpha), atan2(gamma1, alpha);
- return theta0, Vector3.new(dx/alpha*cos(theta0), sin(theta0), dz/alpha*cos(theta0))*speed,
- Vector3.new(dx/alpha*cos(theta1), sin(theta1), dz/alpha*cos(theta1))*speed;
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement