Setting up collision

Hi,

for some reason my PlayerModel is flying away (upward) from my world.
What am I missing?

[java]public void simpleInitApp() {
bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);

    speed = 10.0f;
    
    //World
    Spatial world = assetManager.loadModel("Scenes/city/sound_city.j3o");
    world.setLocalScale(2.0f);
   
    CollisionShape worldcshape = CollisionShapeFactory.createDynamicMeshShape(world);
    RigidBodyControl rworld = new RigidBodyControl(worldcshape,123.0f);
    bulletAppState.getPhysicsSpace().add(rworld);
    rworld.setGravity(new Vector3f(0f,-9.81f,0f));
    world.addControl(rworld);
    rootNode.attachChild(world);
    
    //Player
    player = assetManager.loadModel("Models/player/player.j3o");
    playerNode.attachChild(player);
    CollisionShape playerShape = CollisionShapeFactory.createDynamicMeshShape(player);
    RigidBodyControl plr = new RigidBodyControl(playerShape,120.0f);
    plr.setGravity(new Vector3f(0f,-9.81f,0f));
    plr.setMass(10f);
    bulletAppState.getPhysicsSpace().add(plr);
    
    player.addControl(plr);
    rootNode.attachChild(playerNode);
    [/java]

I’d ask several questions:

  1. you’ve given the world itself mass, why? Are you sure its not the world falling away from you? “new RigidBodyControl(worldcshape,123.0f)” This constructor gives the world a mass of 123kg. Assuming you want the world stationary its mass should be 0 or it should be set as kinematic (the former unless theres a specific reason otherwise)
  2. are you accelerating away from the world (indicating either the above, or a force is pushing you upwards) or are you violently thrown out of the world at what seems close to an infinite speed which would indicate that the player is in an illigal position (inside the world?) to start with and the physics engine is coping with that in the only way it can
  3. why are you setting gravity on an object by object basis? This should be unnessisary unless different objects experience different gravity
2 Likes

nice explanations :). I think #1 is the most likely cause here