Physics in Nu - bryanedds/Nu GitHub Wiki
TODO: basic content.
Nu has two default physics engines, Box2D.NET Physics for 2D and Jolt Physics for 3D. It also has the legacy Aether Physics for 2D that you can opt-into via your NuPlugin.
Fast Imperative Physics Behind a Purely Functional API?
This might seem impossible, but with a technique we developed, it is actually entirely possible to wrap any imperative representation behind a purely functional API so long as it can support certain operations -
TODO: more detail.
Synchronized or Manual Physics Motion
You can set the PhysicsMotion property of a physics-based entity to ManualMotion to prevent changes to the entity's transformation properties from being automatically synchronized with the physics backend. However, enabling ManualMotion also means that whenever you need to change the physical transformation of such an entity, you must do so via a function call such as World.setBodyLinearVelocity or World.setBodyCenter. Changing an entity's transformation via its transform properties will have no effect on its physical representation when in ManualMotion.
More detail from a discord exchange -
bryanedds — 7:53 PM
@fswadling - have you tried using `ManualMotion`?
`ManualMotion` allows you to manually handle body transform events from the physics engine. You can then apply that
directly to the pure data representation from which you can bind the player entity dynamically via ImSim or MMCC.
Gameplay movement of said player entity can then be done with corresponding calls to `World.setBodyLinearVelocity`
or `World.setBodyCenter`.
Omni Blade's AvatarDispatcher uses this sort of approach to preserve unidirectionality.
In fact, preserving unidirectionality is the exact reason `ManualMotion` was created.
Without it, physics-driven entities force the sort of bidirectionality on MMCC that it can't handle well.
Same is true of ImSim with a pure data representation.
Although if you're using a pure data representation in ImSim, you lose a lot of its advantages and perhaps should be
using MMCC...
bryanedds — 8:07 PM
Setting ManualMotion -
https://github.com/bryanedds/Nu/blob/8992688a72bf5e69e24e4a8d661bfc441a5c4533/Projects/Omni%20Blade/Avatar/AvatarDispatcher.fs?plain=1#L42C10-L42C46
Applying movement velocity on input -
https://github.com/bryanedds/Nu/blob/8992688a72bf5e69e24e4a8d661bfc441a5c4533/Projects/Omni%20Blade/Field/FieldDispatcher.fs?plain=1#L720C1-L725C99
Warping character such as through a portal -
https://github.com/bryanedds/Nu/blob/8992688a72bf5e69e24e4a8d661bfc441a5c4533/Projects/Omni%20Blade/Field/FieldDispatcher.fs?plain=1#L772C1-L774C106
The important thing to understand is that the solution to this sort of issue is to remove the bidirectionality like
`ManualMotion` does rather than trying to 'fix it up' via hacks and such.