Physics doesn't update

Hi,

I am new in jME (java Monkey Engine). I am doing my master project about a smart home simulator. I decided to do this project with jME.

Right now, I have a 3D model into my simulator, the next step I want to do It’s control the main door of my virtual house, so, I followed this tutorial and I could implement exactly I wanted.

I tried opening and closing the door, and I got. But the problem is the physics, when the door is opening you can see how the door is opening, but when I try to cross the door I can’t , I know I can do a physics layer into the object but when I try to do this the control disapear.

I have a class which control my main door but the problem is that I can’t update the physics.

This is the control code:

[java]

package control;

import com.jme3.bullet.collision.shapes.CollisionShape;
import com.jme3.bullet.collision.shapes.CompoundCollisionShape;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.bullet.util.CollisionShapeFactory;
import com.jme3.math.FastMath;
import com.jme3.math.Matrix3f;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.control.AbstractControl;
import com.jme3.scene.control.Control;
import mygame.Main;

public class OpenDoor extends RigidBodyControl{

static final float PI = 3.14159265359f;    
private float speed = 5;
private float inipos = 0f;
private boolean action = false; //true=opening, false=closing
RigidBodyControl myRigidBody;

public OpenDoor() {
   
}

public OpenDoor(CollisionShape sceneDoor, int i) {
    super(sceneDoor,i);
    
}

@Override
public void update(float tpf) {
    
    Quaternion q = new Quaternion();
    q.fromAngles(0, -90, 0);
    
     spatial.setLocalRotation(q); 
     super.update(tpf);
    
    /*float angle;
    float angleRads;
    angle = speed;
    angleRads = (angle * PI)/180;
    if(action==true){
        //counter = counter + angleRads;
        if(Math.abs(spatial.getLocalRotation().getY()*2.2-inipos)<PI/2){
            spatial.rotate(0, -angleRads,0); 
            
        }
        
    }else{
        
        if(spatial.getLocalRotation().getY()*2.2-inipos<0){
        spatial.rotate(0, angleRads,0);
        }            
        
    }          

*/
}

public Control cloneForSpatial(Spatial spatial){
    //save initial position
    inipos = (float) (spatial.getLocalRotation().getY()*2.2);
            
    OpenDoor control = new OpenDoor();        
    control.setSpeed(speed);
    control.setSpatial(spatial);
           
    return control;
    
    
}

/**
 * @return the speed
 */
public float getSpeed() {
    return speed;
}

/**
 * @param speed the speed to set
 */
public void setSpeed(float speed) {
    this.speed = speed;
}

/**
 * @return the action
 */
public boolean isAction() {
    return action;
}

/**
 * @param action the action to set
 */
public void setAction(boolean action) {
    this.action = action;
}

public void actionDoor(){
  
   setAction(!action);
  
}

public Object getRigidDoor() {
    return myRigidBody;
}

}[/java]

If you want the physics collision shape to move along with the spatial enable kinematic mode.

1 Like
@normen said: If you want the physics collision shape to move along with the spatial enable kinematic mode.

I’ve activate kinematic mode, but doesn’t work:

[java] public void setDoor(Spatial door){

CollisionShape sceneDoor =
        CollisionShapeFactory.createMeshShape(mainDoor);

rigidDoor = new OpenDoor(sceneDoor, 0);
rigidDoor.setSpatial(mainDoor);
rigidDoor.setKinematic(true);
//door.rotate(0, (float)Math.PI/2, 0);
door.addControl(rigidDoor);
bulletAppState.getPhysicsSpace().add(rigidDoor); 

}[/java]

I’ve tried to activate PhysicsLocal but doesnt’ work as well.

[java]rigidDoor.setApplyPhysicsLocal(true);[/java]

might have to update something?

Why do you use setSpatial? I think its time to read the manual for you.

@normen said: Why do you use setSpatial? I think its time to read the manual for you.

I’ve read the manual, I’ve been basing on examples. I am going to read again, maybe I have more lucky.

Thanks!!! If I can’t do anything I will comeback for answer XD.

@goltara said: I've read the manual, I've been basing on examples. I am going to read again, maybe I have more lucky.

Thanks!!! If I can’t do anything I will comeback for answer XD.

No example uses setSpatial and its javadoc says its an internal method thats not to be used by users, so what did you read? You set the control to the spatial and not the other way around.

@normen said: No example uses setSpatial and its javadoc says its an internal method thats not to be used by users, so what did you read? You set the control to the spatial and not the other way around.

Probably you’re right, I am doing a lot of test and maybe I put this sentence doing test.

Yeahh, I’ve got it, The problem was that I had to scale the Spatial, I 've showed the debug mode and I could solve it.

[java]bulletAppState.getPhysicsSpace().enableDebug(assetManager);[/java]

Thank you show much, I’ve been two days with this.

1 Like