Draw trajectory of RigidBody2D

Godot Version

v4.3

Question

How can I draw trajectory of RigidBody2D (ignoring any collisions). I have set RigidBody2D’s linear and angular damping to 0 and mode to replace. And drew the path using s = ut + 0.5at^2. For some reason the actual trajectory falls behind the calculated one. what could be the problem here.

  1. Are you taking into account the game’s gravity?
  2. Is there a physics material added to the object that would create air resistance?

Yeah I have gravity and a in that motion formula is gravity (Vector2(0, 980)). And I did nothing but set RigidBody2D’s damping (linear and angular) mode to replace. So the material is default value.

1 Like

What are u and t?
If the trajectory height is a function of the x-position, you need to divide by the rigidbody’s horizontal velocity because the faster it goes, the less it will fall per distance travelled

s = ut + 0.5at^2 is physics formula for displacement under an acceleration. Here s is displacement u is initial velocity a is acceleration (in this case gravity) and t is time which I use as 1/60

1 Like

How do you move the body?

1 Like

How are you plotting the trajectory of an objecting using only one dimension? Your plot should be x, the horizontal position , and s, the vertical position.

For now I am testing to see whether I can predict the trajectory. For that I am placing the RigidBody2D (with collision shape rectangle) bottom left of the screen and set linear velocity up right direction.

s, a, u are Vector2

I have found the problem. When the engine calculating there is error in precision because of floats I guess. But because I am using formula there is hardly any error. Which causes real trajectory to fall behind. So I had to calculate manually frame by frame using delta as 1/frame_rate.

You should use physics tick rate then, not frame rate.

1 Like