0 votes

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:

setappliedforce(thrust.rotated(rotation) + gravity)
setappliedtorque(rotationdir * spinthrust)

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:

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.

in Engine by (267 points)
edited by

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.