How to calculate trajectory of RigidBody2D?

Godot Version 4.2.1

I am making game like angry bird. I want to show the trajectory of the object.

The way I achieve it is using RigidBody2D. Prevent it falling I am setting freeze to true and freeze mode to static. And store position of mouse press and calculating difference (delta) using mouse motion. On the mouse release I calculate initial velocity (vector) and and set it to rigid body’s linear velocity and set freeze to false.

And I am calculating trajectory using s = ut + 12 at2. where u is initial velocity a is gravity and t is time.

All are fine. But my RigidBody2D did not follows the my calculated. It’s trajectory always smaller than calculated trajectory. So I changed linear_damp_mode to Replace. Now the error is smaller but not equal.

What I am doing wrong here please help me.


light blue is RigidBody2D’s trajectory
blue is calculated trajectory

Hello, I managed to draw the trajectory exactly matching with the RigidBody2D by
creating a vector from the "1⁄2 at2 " and adding its “y” value to the velocity. The below code calculates the position of the object in each frame;

var gravity_vector = Vector2.ZERO * ((gravity * (delta ** 2)) / 2)
velocity.y += gravity * delta + gravity_vector.y
position += velocity * delta

Initially it was not matching for me as well but then I changed the “linear_damp_mode” to “replace” after I saw your comment :smile: and now it seem to be working! Thanks a lot for that.

1 Like

What is this line of code doing? Isn’t this just a 0 Vector. I suppose this is Vector2.ONE or Vector2.DOWN.