0 votes

I am planning to design a game where the movement of object controlled by the user is governed by external forces. Those forces depend on current geometry of the object (user controlled) and also depend on current object velocity.

My question is:
Continuous variable applied forces over a RigidBody2D should be included in _fixed_process() or should I use _integrate_forces()?

I guess that simply calculating the new forces on each _fixed_process() and reapplying them to the object would be enough. Still not understanding properly how to use _integrate_forces() and when it is needed.

in Engine by (679 points)

2 Answers

0 votes

_integrate_forces() is called as much as _fixed_process(). I use _integrate_forces() whenever I can over it, as it's basically the same but can change the Rigidbody2D's velocity every frame. So, if you will call set_linear_velocity() or set_angular_velocity() every frame, you should use _integrate_forces().

by (1,091 points)

So are you saying we actually don't use fixedpricess() but rather use integrateforces()?

So I put all my control logic etc etc into integrateforces()?

0 votes

From the documentation:

The best way to interact with a RigidBody2D is during the force integration callback. In this very moment, the physics engine
synchronizes state with the scene and allows full modification of the internal parameters (otherwise, as it may be running in a thread, changes will not take place until next frame).

And using _integrate_forces(state) also gives you access to the stateobject, which I like to use as a contact monitor because it gives colliding body information, contact position, contact angle, etc.

by (1,302 points)
