Gravity Does Not Work

Hey everyone. I feel pretty dumb considering I’ve already done this for my player, but my enemy model just does not seem to want to obey the laws of physics. I just can’t seem to find what I’m doing wrong, but my character (a capsulecollisionshape) will not collide with my enemy (also a capsulecollisionshape), and I know that the problem is my enemy because my character collides with the other objects of the environment.

Sorry this is such an up in the air type of question, but I’ve looked at countless examples and I just can’t find the problem. Maybe one of you all can see what’s going on. Here’s the code.

wolfos = (Node) assetManager.loadModel(“Models/Wolfos/default.mesh.xml”);
wolfos.setLocalScale(0.5f);
wolfos.setLocalTranslation(-10.414345f, 0.2258f, 30.31953f);
AnimControl wolfosControl = wolfos.getControl(AnimControl.class);
wolfosControl.addListener(this);
wolfosChannel = wolfosControl.createChannel();
wolfos.addControl(new RigidBodyControl(0));
CapsuleCollisionShape wolfosCapsuleShape = new CapsuleCollisionShape(1,2,2);
wolfosCharacter = new CharacterControl (wolfosCapsuleShape, 2f);
wolfosCharacter.setPhysicsLocation(new Vector3f(-10.414345f, 0.2258f, 38.31953f));
wolfosNode = new Node(“wolfos node”);
wolfosNode.addControl(wolfosCharacter);
rootNode.attachChild(wolfosNode);
wolfosNode.attachChild(wolfos);
bulletAppState.getPhysicsSpace().add(wolfosCharacter);
wolfosCharacter.setJumpSpeed(20f);
wolfosCharacter.setFallSpeed(50f);
wolfosCharacter.setGravity(50f);
wolfosChannel.setAnim(“Wolfos Idle”);

I know that the code for the environment rigidbodycontrol is correct because it works with my character. Thanks again!

[java]wolfos.addControl(new RigidBodyControl(0));[/java]

0 mass is only for static controls and also, you seem to have attached your enemy to the same node which has your character’s CharacterControl attached.

My enemy does collide with the environment but not my character. >.< What you said makes sense, but what you see up there is all the code that I have associated with my enemy. I also changed the rigidbodycontrol to a real number, and it didn’t do anything. I’m lost >.<

i think that the problem is that you and your characters are charactercontrol. It’s doesn’t really matter if it’s a capsulecollisionshape or whatever, the important thing is what you do with it (“the shape doesn’t matter, only what you do with it does” ^^)

You need to understand that the charactercontrol class is not at all like the rigidbodycontrol. The charactercontrol is kinematic, and it means what is doesn’t collide well with other kinematic for exemple.

Try with the “bettercharactercontrol” instead. However, the bettercharactercontrol has also some drawback.

Is it possible to assign gravity to a rigidbodycontrol so that I do not have to bother with the charactercontrol at all?

@bubuche said: i think that the problem is that you and your characters are charactercontrol

That was my initial thought, but on inspecting his code, there is only one CharacterControl

@007-Winner said: Is it possible to assign gravity to a rigidbodycontrol?

yes, they have a setGravity method

Thanks for the quick response. I updated the code to make the enemy a rigidbodycontrol. The gravity certainly works, BUT he falls straight through the floor. Is there an issue with the two rigidbodycontrols colliding? If it helps any, a little while after he falls through the floor I get one of those nullpointerexceptions. Anyhow, here is the updated code.

wolfos = (Node) assetManager.loadModel(“Models/Wolfos/default.mesh.xml”);
wolfos.setLocalScale(0.5f);
wolfos.setLocalTranslation(-10.414345f, 0.2258f, 30.31953f);
AnimControl wolfosControl = wolfos.getControl(AnimControl.class);
wolfosControl.addListener(this);
wolfosChannel = wolfosControl.createChannel();
CollisionShape wolfosShape;
wolfosShape = CollisionShapeFactory.createMeshShape((Node)(wolfos));
rigidWolfos = new RigidBodyControl(wolfosShape, 1);
wolfos.addControl(rigidWolfos);
rootNode.attachChild(wolfos);
bulletAppState.getPhysicsSpace().add(rigidWolfos);

you shouldn’t have a mesh shape with a mass (thats for static stuff), create a hull shape if you want it to be dynamic

Well, it definitely worked. He’s just a little… wobbely, and it’s very easy to push him around. Even so, thank you for all of your help. What do you think I should do about his rather unbalanced state?

You may want to add a BetterCharacterControl to the character.

if you have only one charactercontrol in your code, it means that your ennemies don’t use a charactercontrol (^^). So : how do you move them. Ok, to make my point clear : if you move them with call to “warp” they will not collide with the charactercontrol. And, the charactercontrol cannot be pushed by a moving ennemy, as it’s a kinematic control.

You should try to create a simple test case if you still have the problem.

EDIT : and also, if you character is moving in a direction and an other rigidbodycontrol is moving in the opposite direction with a “setSpeed” called at each frame, they will likely go through each other.

And i don’t see the relation with “gravity” in your problem.