I have Spatial - player and two controls attached to it.
The first is CharacterControl and the second is my custom PlayerControl.
I attach CharacterControl the first and then, when I attach my PlayerControl in it’s overridden method setSpatial I get player’s CharacterControl instance via spatial.getControl(CharacterControl.class) (spatial is default field in every control that refer to spatial to wich it attached - player in my case).
In my PlayerControl I have mappings and listeners set up. According them I do manipulations with CharacterControl, for example moving it. I mean, I manipulate one control from another through one spatial.
I think it isn’t best practice. But how can I create custom control for player if player isn’t Spatial - he is CharacterControl and in fact I control it’s CollisionShape and not common Spatial?
Maybe there is the best way of player creating?
Now I don’t like way of creating player via CharacterControl because of I must work with it’s CollisionShape instead of usual Spatial. What if I want to add 3D model to my player? CollisionShape is only physics object, it isn’t visible in game. And I want to my player could be reflected in the mirror for example. Is there a way to add a 3D model to CharacterControl? It is additional problem to that I have Spatial - player that used only for Controls managing and I don’t use it as real Spatial object(with it’s position, translation, textures etc). I use it only for communication between controls.
Spatial easily can became a physics object by adding RigidBodyControl to it. This case I’m adding physical properties to visual object. But in case CharacterControl I want to understand how to add visual properties to physics object
Add the CharacterControl to your 3D model. Now you have your 3D model. Now your model is a Physics Object. To move and rotate it you must do it to the physics control, and not the spatial. This is because the physics engine is controlling the model now. Gravity and collision will move the spatial - it is in control of it. So you must also tell the physics engine to move it - that is why you talk to the physics object and not the spatial anymore.
To add key mappings you should use an AppState - because it’s a state of the game. If you pause the game you disable the appstate and enable another “menu” appstate.
the physics object is not “visual”. The meshes are data for the physics engine to find collisions.
First, I suspect if you described what your “player control” is doing that it’s actually a singleton and doing the work that an app state would be doing.
Second, there seems to be some misunderstanding about how to setup a physics character?
Is it that you want a model with the physics object or not? Usually, one has a model with the physics object but if the player is ‘invisible’ to himself then you wouldn’t. But it’s not clear to me which one you are trying to achieve.
Ok, thank you all for help. I will re-read your answers once again and most likely will try to do this this via the AppState
But yesterday I have encountered a little problem with controlUpdate method of my control.
In docs I read that control’s update method executed automatically from moment I add control to spatial. But it wasn’t. Did I understand correctly, additional condition is control’s parent spatial must be added to root node?