- Home /
Trajectory predetermining
How do I predetermine the trajectory end point or sigle point of trajectory like in this image ?
Picture is in 2d space, but i want to predetermine X,Y and Z
Remember that link you got posted in your last question? I followed that, and am currently quite happily using it to draw trajectory lines for thrown weapons in my brawler. The answers are out there, you just have to look!
Find a high school physics text book. $$anonymous$$e has a problem in it like that. ( People try to shoot a monkey that falls out of a tree, but of course the bullet will fall too cause of gravity )
Answer by Peter G · Oct 30, 2011 at 06:02 PM
The physics behind it isn't too hard. The simplest way to do it would be to do a simple parametric equation. Given you know the launch direction and magnitude, you can find the projectiles position as a simple function of time:
Vector3 launchVelocity;
Vector3 launchPos;
public float gravity;
public Vector3 ObjectPos {
get {
float yPos = launchVelocity.y * time - .5f * gravity * time * time + launchPos.y;
//height of an object as a function of time (ignoring air resistance)
// h(t) = vi * t + .5g*t^2 + startHeight
var xzPos = new Vector3(launchPos.x , 0 , launchPos.z) + new Vector3(launchPos.x , 0 , launchPos.z) * time;
//horizontal velocity is unaffected by time or vertical height.
//So just: startPos + vi*t
return yPos + xzPos;
}
}
This will give you the position of your object at any time after launch. To figure out when it lands, just figure out when the height is equal to the round height. If you have level ground, this will happen at t = 2 * (yVel / gravity). And obviously, this isn't working code, the ideas are all there with some stuff written in code format, but its mostly just written to get all the ideas across.