I have problems with predicting trajectory I'm using: Code (csharp): Vector2 startPos; float power = 10.0f; float interval = 1/30.0f; GameObject[] ind; void Start (){ transform.rigidbody2D.isKinematic = true; ind = new GameObject[dots]; for(int i = 0; i<dots; i++){ GameObject dot = (GameObject)Instantiate(Dot); dot.renderer.enabled = false; ind[i] = dot; } } void Update (){ if(shot) return; if(Input.GetAxis("Fire1") == 1){ if(!aiming){ aiming = true; startPos = Input.mousePosition; ShowPath(); } else{ CalculatePath(); } } else if(aiming !shot){ transform.rigidbody2D.isKinematic = false; transform.rigidbody2D.AddForce(GetForce(Input.mous ePosition)); shot = true; aiming = false; HidePath(); } } Vector2 GetForce(Vector3 mouse){ return (new Vector2(startPos.x, startPos.y)- new Vector2(mouse.x, mouse.y))*power; } void CalculatePath(){ ind[0].transform.position = transform.position; //set frist dot to ball position Vector2 vel = GetForce(Input.mousePosition); //get velocity for(int i = 1; i < dots; i++){ ind[i].renderer.enabled = true; //make them visible Vector3 point = PathPoint(transform.position, vel, i); //get position of the dot point.z = -1.0f; ind[i].transform.position = point; } } Vector2 PathPoint(Vector2 startP, Vector2 startVel, int n){ //Standard formula for trajectory prediction float t = interval; Vector2 stepVelocity = t*startVel; Vector2 StepGravity = t*t*Physics.gravity; Vector2 whattoreturn = ((startP + (n * stepVelocity)+(n*n+n)*StepGravity) * 0.5f); return whattoreturn; } Using this, I get wrong trajectory. 1. It's like gravity doesn't drag trajectory down at all, and yes i know that gravity is weak because: Code (csharp): t*t*Physics.gravity = 0.03^2 * vector2(0, -9.8) = vector2(0, -0.00882) But that is the formula :S 2. Since gravity is low, velocity is too strong. Here is the video: http://tinypic.com/player.php?v=1z50w3m&s=5 Trajectory formula form: http://www.iforce2d.net/b2dtut/projected-trajectory What should I do? I found that if I set StepGravity to something stronger like (0, -0.1) and devide startVel by 8 I get nearly right trajectory, but i don't want that, I need true trajectory path.
Try: Code (csharp): Vector2 PathPoint(Vector2 startP, Vector2 startVel, float t) { return startP + startVel * t + 0.5f * Physics2D.gravity * t * t; } For startVel in units per second, this tells you the position of the projectile after t seconds. Edit: if you want to keep using the formula you were using before, I think you multiplied too many copies of "t" into the step gravity term, but it doesn't really make sense to use that kind of formula unless you synchronise the 'interval' with the physics timestep. In practise it is simpler to use a the general continuous integration formula, and it should give results that are just as accurate in general, except in the case where gravity is extremely high.