Models and physics center

Quick question, I’ve always had this problem when using physics in my application. For some odd reason the model will be vertically offset so that the bottom of the mesh(feet) is in the center of the physicsBox. I normally center before attaching the physicsNodes to fix the problem but i wanted to know if it was a normal occurrence or something i did wrong when i exported or modeled them.

I guess you have the model attached to a rootNode with some translation when you create the collisionshape.

No the second the model is given to the player the physicsController the node itself isn’t references outside of that time; however, this also occurs in tests and another project i was working on. Its never a big deal though because Spatial.center() fixes things. I was just curious

I cant exactly grasp whats happening on your side, can you post example code? Also, are you using the new Control system already?

Yeah I’m using the new control system and realized the problem was still occurring so i decided to ask



This happens with all of my models. I asked this question before but never really got an answer since no One understood what i meant but does it matter the placement of the pinkNode in Blender?



[java]

/*

  • To change this template, choose Tools | Templates
  • and open the template in the editor.

    */



    package test;



    import com.jme3.app.SimpleApplication;

    import com.jme3.bullet.BulletAppState;

    import com.jme3.bullet.PhysicsSpace;

    import com.jme3.bullet.collision.shapes.BoxCollisionShape;

    import com.jme3.bullet.control.PhysicsCharacterControl;

    import com.jme3.bullet.control.PhysicsRigidBodyControl;

    import com.jme3.bullet.util.CollisionShapeFactory;

    import com.jme3.material.Material;

    import com.jme3.math.ColorRGBA;

    import com.jme3.math.Vector3f;

    import com.jme3.scene.Geometry;

    import com.jme3.scene.Spatial;

    import com.jme3.scene.shape.Box;



    /**

    *
  • @author Kyle Williams

    */

    public class PhysicsBug extends SimpleApplication{



    public static void main(String[] args){

    PhysicsBug app = new PhysicsBug();

    app.start();

    }



    @Override

    public void simpleInitApp() {

    //Change Background Color

    viewPort.setBackgroundColor(ColorRGBA.DarkGray);

    //Quickly Set Up Physics

    BulletAppState bApp = new BulletAppState();

    getStateManager().attach(bApp);

    //SetsUp Lights

    com.jme3.light.DirectionalLight dl = new com.jme3.light.DirectionalLight();

    dl.setDirection(getCamera().getDirection().normalizeLocal());

    dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));

    rootNode.addLight(dl);

    //SetsUp A Floor To Land On

    setUpFloor(bApp.getPhysicsSpace());

    //SetsUp The Model

    setUpCharacter(bApp.getPhysicsSpace());

    }



    public void setUpFloor(PhysicsSpace pSpace){

    Box b = new Box(Vector3f.ZERO, 1, .1f, 1);

    Geometry geom = new Geometry(“Box”, b);

    geom.updateModelBound();



    Material mat = new Material(assetManager, “Common/MatDefs/Misc/SolidColor.j3md”);

    mat.setColor(“m_Color”, ColorRGBA.Blue);

    geom.setMaterial(mat);



    PhysicsRigidBodyControl physicsGeom=new PhysicsRigidBodyControl(CollisionShapeFactory.createMeshShape(geom),0);

    ((PhysicsRigidBodyControl)physicsGeom).attachDebugShape(getAssetManager());

    geom.addControl(physicsGeom);



    rootNode.attachChild(geom);

    pSpace.add(geom);

    }



    private void setUpCharacter(PhysicsSpace pSpace) {

    Spatial spat = getAssetManager().loadModel(“Models/Alex/Alex.j3o”);



    BoxCollisionShape bcs = new BoxCollisionShape(((com.jme3.bounding.BoundingBox) spat.getWorldBound()).getExtent(null));

    PhysicsCharacterControl pSpat = new PhysicsCharacterControl(bcs, 1f);



    spat.addControl(pSpat);

    pSpat.attachDebugShape(getAssetManager());



    rootNode.attachChild(spat);

    pSpace.add(pSpat);

    }

    }

    [/java]



Its definitely with the model; however, as I’ve loaded a lot of other models that were not mine and received the same issue. Sinbad from the jme repo for example his mesh is a little below the bounding box. Oto seems to be the only perfect one I have loaded tried though

It’s possible Oto is centered exactly at the origin, still there’s no problem with just translating the collision shape (or model) so one fits the other.