![]() |
RigsofRods
2023.09
Soft-body Physics Simulation
|
FreeForces are global, persistent forces which act upon one node of one actor each. They exist separately from actors and their existing hook/tie/rope interactions. This means they do not interfere with actor N/B or any of the existing linking logic. They're intended for creating special physics effects which aren't supported otherwise, like making party baloons fly. They're intentionally only accessible from scripts to maximize their flexibility and limit maintenance of the codebase.
To manage FreeForces, you use game.pushMessage()
with MSG_SIM_ADD_FREEFORCE_REQUESTED
, MSG_SIM_MODIFY_FREEFORCE_REQUESTED
or MSG_SIM_REMOVE_FREEFORCE_REQUESTED
.
Parameters common to ADD/MODIFY requests:
game.getFreeForceNextId()
to obtain an unique sequential ID.FREEFORCETYPE_DUMMY
, FREEFORCETYPE_CONSTANT
, FREEFORCETYPE_TOWARDS_COORDS
, FREEFORCETYPE_TOWARDS_NODE
game.getCurrentTruck().getInstanceId()
, or if you're in an actor-script, then you can do thisActor.getInstanceId()
// BeamClass@ thisActor
is automatic global variable for scripts bound to actors.FREEFORCETYPE_CONSTANT
:Additional parameters for FREEFORCETYPE_TOWARDS_COORDS
:
game.getPersonPosition()
will target it at position where character is standing AT THE MOMENT.Additional parameters for FREEFORCETYPE_TOWARDS_NODE
:
Note when any of the actors involved in a FreeForce (be it the base one or target one), the freeforce is deleted.
Example from the PartyBaloon demo mod:
Keep in mind that the physics simulation runs at 2khz (2000 steps per second), while scripts run in sync with FPS. That's why there's no option to add temporary/one-off force impulses from scripts - you are responsible for adding the persistent force, monitoring and adjusting it as needed, and then removing it when no longer necessary. You can create the forces as dummy and then change their type later as needed.
Below is the demo PartyBaloon mod. It weights only 12 grams (0.012 Kg) and under our simulation it moves very slowly, not bypasing a certain threshold, regardless of pull force applied to it. By default, it will just fly off (you can grab it with mouse) but you can use console variables to bind it somewhere: The script bundled with the baloon will read these variables and create an additional FreeForce towards either the spawn position or given node on given actor. Download PartyBaloon-12grams.zip
Note about a quirk: Chaining object access like game.getCurrentTruck().getInstanceId()
will not work. You must do either game.getCurrentTruck().getHandle().getInstanceId()
or BeamClass@ b = game.getCurrentTruck(); b.getInstanceId()
because the return type isn't BeamClass@
but rather BeamClassPtr@
. This is a quirk of our present reference-counting mechanism. More info is at https://github.com/ohlidalp/RefCountingObject-AngelScript.
This page is archived from original GitHub PR and respective commit messages.