Physics interaction between CharacterControl and RigidBodyControl?

I’m trying to set up a test game where RigidBodyControl objects are moving in the physics space and are able to interact with, push, bump, knock, etc, CharacterControl objects. The amount of force transmitted should be in proportion to the mass and velocity of both bodies. Is there a way to do that? Looking at the JavaDoc, it appears only rigid bodies have the concept of “mass” implemented, so it looks like the character side of the physics tree is SOL with regards to interacting in a “massy” way with rigid bodies? I’m curious why the concept of mass, which seems so central to any physics object, wouldn’t be implemented at the top level in PhysicsCollisionObject so that all physics objects could participate in full physical interactions. Or, being a newbie to jme3, maybe my lack of complete understanding is showing… :slight_smile:



I guess my basic question is, is there a way to have a character controlled body that can be bounced around by non-character rigid bodies? My current character control will stop cold even the largest, most massive rigid bodies.

The character is only a simple physics simulation. If you use a PhysicsCollisionListener you get informed about collisions with the character too and can move it accordingly to your liking.

maybe you get something useful out of http://hub.jmonkeyengine.org/groups/user-code-projects/forum/topic/complete-forcecharactercontrol/

@normen: Thanks for the info. Has there been any thought given to implementing the character side with full physics? That seems like a weakness in the current design to me.



@nego: I’ll definitely take a look at that class. Sounds like it may be useful. Thanks.

davepete said:
Has there been any thought given to implementing the character side with full physics? That seems like a weakness in the current design to me.

Ask the bullet guys. Balancing a character with full physics is really hard.. Something like a fly-by-wire system.. The area in your brain that allows you to walk and not fall over is pretty large and took some time to develop, its even harder for a computer.. Just try to make a rigidybody stay in one place by applying forces and you will see what I mean. So the easy (and CPU efficient) solution is to lock the axes etc. so you don't fall over. The character is in fact a combination of a kinematic rigidbody and a ghost control to check for overlaps.
normen said:
Ask the bullet guys. Balancing a character with full physics is really hard.. Something like a fly-by-wire system.. The area in your brain that allows you to walk and not fall over is pretty large and took some time to develop, its even harder for a computer.. So the easy (and CPU efficient) solution is to lock the axes etc. so you don't fall over. The character is in fact a combination of a kinematic rigidbody and a ghost control to check for overlaps.


Yeah, going that far would be pretty tough, for sure. I guess I was thinking more along the lines of just implementing the RigidBody type physics on the collision shape associated with the character. That way outside physics forces from rigidbodies could act against the characters just like they do for any other rigidbody objects.
davepete said:
Yeah, going that far would be pretty tough, for sure. I guess I was thinking more along the lines of just implementing the RigidBody type physics on the collision shape associated with the character. That way outside physics forces from rigidbodies could act against the characters just like they do for any other rigidbody objects.

Its the same thing. As soon as you apply "normal" physics to the body its uncontrollable and you *have to* do all that.

try this the coder has it in a very stable state, its not necessarily what you are looking for and may still have gotchas but it looks good…

normen said:
Its the same thing. As soon as you apply "normal" physics to the body its uncontrollable and you *have to* do all that.


So, if I use a collision listener, calculate the impact forces from the rigidbody objects and move my character, it will become uncontrollable? Obviously I haven't tried this yet so I can't speak from direct experience, but hopefully I'm not going to break my character's controllability in doing that.

… no, you were talking about adding “full physics” to the character. You can try that, just use a RigidBodyControl instead of the CharacterControl and try to control it via addForce() etc. The solution of listening to the collisions and then moving the CharacterControl accordingly was my proposed “simple solution”.

but then again, wouldnt “full physics” be creating a RagDoll and applying forces to it? :slight_smile: Btw I tried to make the RagDoll walk and i failed tremendously :slight_smile: There are however posts from various users (Empire_Phoenix comes to my mind) who managed to solve sliding / walking / stepping-up & down with RigidBodyControls.

In some games you have a quasi CharacterControl attached to a character and upon impact of some big forces (like force push in star wars like games) they substitute the CharacterControl with a RagDollControl, making the collision quite realistic, at least it looks like that :slight_smile:

Yes exactly. But @davepete doesn’t just want it to react like a “normal” physics object when its dead but all the time… Thus he’d have to do the fly-by-wire stuff all the time.

I wasn’t really asking for the character to respond to external forces in fully animated “ragdoll” fashion. If that’s the way you interpreted it, normen, then I was simply not clearly stating things in my ignorance of what I was asking for. :slight_smile: For the test game I am writing, I was requesting that a character simply be able to respond to external forces as a rigid body. That would still be an improvement over the mostly non-responsiveness the character controls currently appear to have wrt RigidBodyControls.



All that being said, nego’s ragdoll control substitution suggestion might be effective for the case I’m considering. The collision listener should be able to kick off the substitution and allow the ragdoll control to absorb the collision and get moved around, right? A couple of questions along that line, then. First, I still don’t see any concept of mass in either the RagDollControl or Bone classes. How do collision forces and movement results get calculated without knowing the mass of the impacted object? Second, in this scenario will I be able to find the area of the body that is hit in the collision? At some point down the road I’d like to be able to react to a hit of a specific arm, leg, head, etc.

From my perspective, you have 4 options, ordered from less diffcult to more difficult, thus less accurate to more accurate:



1)Stick with CharacterControl and move it manually by implementing PhysicsCollisionListener.

You can get the linear velocity and mass of the PhysicsRigidBody that collided. Based on these values, you can calculate the force the PhysicsRigidBody collided. You can reduce that incoming force by manually reducing it by a factor (hence your characters “mass” ). After you you have calculated this heavily “approximated” force to be applied to the CharacterControl, you can move the CharacterControl accordingly.

The ForceCharacterControl (posted in the link above) helps you convert the force into movement → no rotation though.



2)Use a RigidBodyControl for your character. This is a more realistic approach, however you will have to manually apply forces and set attributes to be able to move, jump, step up /down on stairs and not to slide down a hill. There have been members that were successful in this approach, however, this involves much tweaking. If you dont want any rotation to happen to the RigidBody, which could induce camera shaking, use the method RigidBodyControl.setAngularFactor(0f)



3)As you mentioned in your last post, substitute the RagDollControl for your CharacterControl when something collides with the character. However you should note that you have to substitute the CharacterControl before any collision happens, as the Physics System wont be able to apply the forces correctly (you can do that by implementing a PhysicsGroupCollisionListener). To get back on your question, see https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:ragdoll → the RagDoll consists of many small RigidBodyControls that are connected with hinges and joints. Shooting something at them should correctly move the body part you shot at, and will therefore move the hinge/joint which will move the other body parts too.

This approach could be implemented, but you have to figure it out, how and when you will switch the CharacterControl back on.



4)Use a RagDollControl all the time. → many manual forces to be applied, almost impossible to balance, i dont know if thats a good idea.



EDIT: ad 3) To answer your second question: You can attach a CollisionListener to every body part (which is a RigidBodyControl) to detect what was hit

davepete said:
If that's the way you interpreted it, normen, then I was simply not clearly stating things in my ignorance of what I was asking for.

No I didn't. I told you, just try to keep a RigidBody with a simple Capsule shape floating and upright while you move it. Its hard enough already.
normen said:
No I didn't. I told you, just try to keep a RigidBody with a simple Capsule shape floating and upright while you move it. Its hard enough already.

Wouldnt setAngularFactor(0f) prevent the RigidBody from falling? I can only confirm it for collision with other RigidBodies -> the character will stay upright. I dont know however how gravity affects it (tested only on perfectly even floor)

Yes, but thats not “full physics”.