Hi all,
I’m trying to draw the trajectory of a projectile (aka Angry bird). I managed to do it, however once I launch the projectile it doesn’t exactly follow the trajectory, and I don’t manage to find from where comes the difference…
Here is the code I’m using:
void OnDrawGizmos(){
GameObject player = GameObject.FindWithTag("Player");
float h = 0.0f;
while(player.transform.TransformPoint(PlotTrajectoryAtTime(h)).y >= 0){
Gizmos.DrawSphere(player.transform.TransformPoint(PlotTrajectoryAtTime(h)), 0.2f);
h = h + 0.1f;
}
}
public Vector3 PlotTrajectoryAtTime (float t) {
return startVelocity*t + Physics.gravity*t*t*0.5f + startPoint;
}
public void Update(){
if (Input.GetKeyUp(KeyCode.L)){
GameObject player = GameObject.FindWithTag("Player");
GameObject.Find ("Rock").transform.position = player.transform.TransformPoint(0,startPoint.y,startPoint.z); //the object to launch
Vector3 force = player.transform.TransformDirection(startVelocity); // to launch the rock in the good direction
GameObject.Find("Rock").transform.rigidbody.velocity = force;
}
}
However the trajectory drawn in the Editor is “higher” than the real trajectory followed by the rock… amy idea?
Cheers,
Nicolas