|Topic was automatically imported from the old Question2Answer platform.
I am by now pretty sure there is no dedicated method available in the engine, but maybe someone can point me to some other way. How would one apply torque to a RigidBody2D, at an arbitrary point that does not match its origin?
What do you need the force to do exactly? Do you want the object to rotate around an axis that is not the center of mass? You could use a PinJoint2D if you need the object to rotate around a fixed point.
a_world_of_madness | 2023-06-11 11:02
I need to apply given physical torque at a given point, and have objects linear and angular velocities altered accordingly. What axis it should rotate about would depend on other forces, joints and collisions present. Thanks but pin joint won’t do.
Rpahut | 2023-06-12 07:26
Would this Godot demo project be the solution?
a_world_of_madness | 2023-06-12 08:35
Tried apply_impulse at some point. Problem is how to recalculate from the torque relative to a point into an impulse to apply relative to origin.
It also seem to put the entire impulse into linear velocity, which is not correct for a force acting off center. Would be better off altering velocity directly. Only I have no idea how to approach the math.
Rpahut | 2023-06-12 11:57
But is the behavior of the demo I uploaded correct?
apply_impulse is good for one off forces, like in the example.
apply_central_impulse automatically applies the force at the center of mass of the object, meaning no angular momentum, but
apply_force allow you to specify the offset from center of mass, meaning you will get angular momentum.
In the example I provided, I apply a force off-center that causes the object to rotate, then apply the inverse of same force at the center of mass, which negates the linear velocity, so the object only rotates. The math is pretty simple, it’s just finding the vector from the center of mass to the mouse position, then rotates the vector 90 degrees.
Changing the physics state (angular and linear velocities) directly can easily cause problems if you need to have external forces affect the object as well.
Can you provide more info about the problem you are trying to solve?
a_world_of_madness | 2023-06-12 12:26
Thank you for investing your time a_world_of_madness, really, only applying impulse off center and getting some any angular acceleration out of it is not the same as applying torque off center. I do need help but having to explain the difference I doubt you have the answer so it would be a waste of time for both of us.
Rpahut | 2023-06-12 18:47