Zay-ES Entity for Impulses

Hey. I made an ImpulseComponent to be attached to an entity to apply impulse to another entity. Should I be making new entities every impulse or should I be pooling them?

An entity is just a number.

“124” I just created an entity.

“2843637” I just created another one.

Create all you want.

Now, the real question ultimately is if you really want to be controlling your entities this way. Sometimes a little redesign can save a lot of churn in your components and it largely depends on what else will be using them.

For example, for player-controlled things in me physics systems, I tend to have a special sort of strategy object that I can set to my physics objects. This takes control components from the player and per physics frame gets to make decisions about how to apply that. This strategy object (I’ve called them ‘Movers’ or ‘Drivers’… doesnt’ matter) can then take advantage of things like the collisions and so on to decide what to do. This is generally a more obvious approach when you have written your own physics engine as I have… but it works even with physics libraries.

In that case, your physics objects exist as they will. You have another state that looks for entities with some kind of control state (Mine is usually some flags and a direction… where the flags represent the keys the user is pressing.) This state does the job of registering the appropriate ‘mover’ with the physics system. Some care needs to be taken to be able to register these movers with object that may not have been added to physics yet. (Just in case some event ordering makes one system see it before another.) Then this mover state thingy is responsible for making sure that mover object has the latest player control state.

In the end, controlling a player through impulses with one-two frame delay on contacts and be overly tedious… so a different approach as described above is often easier.

Yeah I haven’t even thought about listening for collisions yet. I’m going to try setting this up. Thanks again.

Okay I know I’ve mentioned this a lot. But would it be proper to just attach a control to the rigidbody? I know that the rigidbodies in the physics system is just a artifact. But still.

Anyways back to how you do it. I don’t understand how the drivers interact with the physics system. do you have a sample that I can look at?

EDIT: MonkeyTrap looks like it does this. right?

EDIT2: Nevermind I don’t think it’s quite what you meant

I have my own body objects so I add a “mover” field to it. If it’s null then nothing happens.

If it’s not null then when I detect collisions I let it know. Before I ‘integrate’ I also let it know so it can do any last minute tweaks to the acceleration. It only touches acceleration. Velocity is 100% in control of the physics integration step as messing directly with velocity can lead to funny things.

I have a MoverState that’s only job is to watch for entities with the MovementState component. (Not an app state… the state of momement.) Basically, It has a direction vector and some flags to denote if it’s walking, running, jumping, etc… Whenever that component changes, the MoverState updates the Mover with the latest data.

Since I have a couple threads going and the physics system runs on its own thread, the only particularly tricky bit is letting the MoverState register Movers before the physics system has a body for it. I just keep them in a map and check when I get a new body. Some other management there is required also.

In bullet you don’t have as direct an access… but you can always extend RigidBody to have whatever fields you want for your own purposes. I did this same thing when using dyn4j… I extend their body class to add my own fields like Entity and Mover.

The reason I want my mover to know about collisions is because then it knows if it’s standing on something, if it’s moving into a wall, etc… It can then decide if it wants to climb over a bump or let the player jump (if not on the ground) or let the player fall (if flying into a wall with nothing under its feet). and so on.

Awesome I understand this. It’s pretty much what I have been doing but I’ve been altering the velocity.

Now for a physics question. When you say " Velocity is 100% in control of the physics integration step," you mean the velocity component right? Since I’m using PhysicsRigidBody I have to change the linearVelocity to move it in the direction I need.

No. I meant velocity… as in the linearVelocity of the physics body.

I never change this except through acceleration (forces and impulses basically). I want my character to be affected by stuff moving in the scene and setting velocity directly will cause issues with that.

…I don’t have a Velocity component at all.

Ahh okay. Thanks. I will have a few more questions later after I play around with this. Don’t worry I am getting close. So less questions

Edit: is applyContinuousForce not implemented?

Okay now say I want to “warp” a physics entity. I’m certain it is safe to setPhysicsLocation? But I’m just making sure

I tested it with JBullet, but you have to make sure you don’t warp the rigidbody into an other rigidbody