Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Robotex |
I want to build my RigidBody2D from different pieces, each of them has own mass. Center of mass point calculated and depends from pieces mass.
I implemented it as RigidBody2D with few CollisionPolygon2D with each script attached that defines mass and main script of root object calculates center of mass point. I’m controlling my body by functions:
set_applied_force(thrust.rotated(rotation) + gravity)
set_applied_torque(rotation_dir * spin_thrust)
But how to do the same with calculated center of mass point?
I see function
void add_force(offset: Vector2, force: Vector2)
but I don’t understand how to use it in each frame. Should I clear all forces and than set it by add_force?
I used that:
set_applied_force(Vector2())
add_force(Vector2(0, 30), (thrust.rotated(rotation) + gravity))
but object moves similar as force applied to center and without rotation.
Maybe I can calculate result force and torque from all forces applied to different points of my body.