Zay-ES Visual, Physics and CharacterControlAppState

Hello once again I have run into an issue with Zay-ES.

My issues is with the player position. So I am using BulletPhysics and my PhysicsAppState implements PhysicsTickListener. And is Added to a physicsState. So I applyChanges at prePhysicsTick. Then set new Position/rotationComponents based on Rigidbodies tied to the entityIds after physics has run in the physicsTick.

This works great for the most part. Except when it comes to moving the character around. I want to be able to override the Position/Rotation/Velocity components from the CharacterControlAppState. However, I have obviously overlooked something and can’t figure the proper way to achieve this.

Can you explain more about why? It might help with solutions.

Physics controlled objects should be moved by the physics engine.

Yes physics objects are fine. The problem is the player entity. When I change it’s velocity I need it to override the velocity on the rigidbody in the PhysicsState. I think that I got it. I think I have to attach the Physics and Visual state last. But my problem now is the I keep getting NPE when I have my VisualState and PhysicsState attached after everything else.

The EntitySets in PhysicsState are not triggering applyChanges() when I have it attached after the other states. So I can’t add the entities to the PhysicsState and it throws NPE…

Character control state sets a velocity component. (Really should be attaching impulse or acceleration components but let’s go with this for a second.)

Then physics state applies the change to velocity. (Which is bad because the physic state should be controlling velocity for most things but here we’ll say that the player is special.)

Then the visual state updates the view.

I don’t see where the issue is. I cannot comment on NPEs without code and stack traces, though. No more than I can diagnose that ails your unicorn. :slight_smile:

Wait so I shouldn’t be changing the VelocityComponent outside of physics?

The NPE is caused by there being no addedEntities(). This only happens if I attach PhysicsState after the GameState to the stateManager… Seems odd.

addedEntities() is not throwing an NPE. Your code is. I guess. I can’t see a stack trace or code or anything.

Your unicorn is sick. I guess it’s in the stomach.

If the entities were already in the entity set when you created it then they won’t show up as being added.

If you are changing a velocity component inside physics then you should not be changing it outside of physics. If it’s only used to communicate to the physics engine then that’s fine.

One writer, basically.

So, going out on a limb without seeing any code… I hate randomly guessing about stuff… but whatever.

Probably when you create your entity set you need to call addFooBars(entitySet) or whatever. And your addFooBars() method should be taking Set… and is the same method you call in your applyChanges() block.

Or you could use the class I referred you to earlier that takes care of this: SiO2/EntityContainer.java at master · Simsilica/SiO2 · GitHub

…just cut and paste if if you like.

Steps to use:
-subclass it to add your own add/update/remove functionality
-instantiate your subclass
-call start() when you want to start pulling entities
-call update() once a frame
-call stop() when done.

1 Like

Stack trace won’t help I’ve looked at it. And addedEntities is how I create the rigidBodies. However, since addedEntities is never triggered when the update pass come tries to:

for (Entity e : entities) {
            PhysicsRigidBody r = rigidBodies.get(e.getId());

There is no rigidBody. NPE.

Edit: we posted at same time. What you just expected. Let me try it.

Yes that worked. Going to give that class for a spin.

By the way, thanks so much. I’ve progressed TONS in the passed couple of days. I finally have a semi working game using Zay-ES. I’m starting to understand the ECS hype

1 Like