I have the ModelState, which works with Model and Position and adds the Spatial and the dyn4j body.
The Spatial has a control that updates its position in order to follow the body.
I have some methods for moving and updating the Position of the entity.
When the Position is changed, I update the Body position so that also the Spatial position is updated.
Question: all of this is a bit convoluted or is the standard way for doing this?
And why have a control on the spatial if you can get the position from the physical body ?
Sounds like you are mixing view with model. ModelState should only care about position and model, and update the spatial. The Dyn4j body lives in a PhysicsState that updates the Position.
Sounds like itās reversed. The Physics should be feeding the Positions.
Normally you have ViewSytem which is solely interested in entities which have model and position/orientation, this system creates/removes/updates only the visuals.
Then you have PhysicSystem which cares for the physic stuff and updates the positions of your physical models.
User inputs are forces which the physicSystem has to apply to player whatever.
But as @asser_fahrenholz already mentioned above you seem to mix it somehow.
Well, Dyn4j is, like other physics libaries, made to do all the heavy lifting on positions, collisions, rotations etc. Feed your input to Dyn4j, then have that do a world-update, extract positions/rotations from Dyn4j-bodies to your models and thus the view.
You mean to say your āHitboxā component also includes position information ? Thereās no reason to have positional information twice. But Iām not sure what you use āhitboxā for.
Yes, as stated above, physics state sets the Position component.
Anything wanting to deal with objects with Positions will then see updates to that component. This might be a model state that updates 3D visuals, it might be a map state that updates markers + labels on a map, etcā¦