-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 float. They're intentionally only accessible from scripts to maximize their flexibility and limit maintenance of the codebase. 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. 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: * 'id' (int) - unique ID of this freeforce, use `game.getFreeForceNextId()` to obtain an unique sequential ID. * 'type' (FreeForceType) - One of `FREEFORCETYPE_DUMMY`, `FREEFORCETYPE_CONSTANT`, `FREEFORCETYPE_TOWARDS_COORDS`, `FREEFORCETYPE_TOWARDS_NODE` * 'base_actor' (int) - Unique actor instance ID, obtain it by `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. * 'base_node' (int) - Node number (0 - 65535) * 'force_magnitude' (float) - the amount of force to apply, in Newton/meters Parameters for `FREEFORCETYPE_CONSTANT`: * 'force_const_direction' (vector3) - constant force direction. Note that Y=up, so to make things float, use vector3(0, 1, 0). Parameters for `FREEFORCETYPE_TOWARDS_COORDS`: * 'target_coords' (vector3) - world position to target. For example `game.getPersonPosition()` will target it at position where character is standing AT THE MOMENT. Parameters for `FREEFORCETYPE_TOWARDS_NODE`: * 'target_actor' (int) - Unique actor instance ID. * 'target_node' (int) - Node number (0 - 65535). 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: ``` // Create the up-force upforce_assigned_id = game.getFreeForceNextId(); game.pushMessage(MSG_SIM_ADD_FREEFORCE_REQUESTED, { {'id', upforce_assigned_id }, {'type', FREEFORCETYPE_CONSTANT }, {'base_actor', thisActor.getInstanceId() }, // `BeamClass@ thisActor`is automatic global variable for scripts bound to actors. {'base_node', UPFORCE_NODE }, {'force_const_direction', vector3(0, 1, 0) }, // Y=up {'force_magnitude', 0.4f } // Newton/meters }); ```
- Loading branch information
Showing
12 changed files
with
373 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.