Hey, maybe the method is just not supposed to work the way I’m trying to use it, but with nightly build 26-JAN-11 it worked fine. The GhostControl (mouthCollisionObj) object should be on a certain location at the model to detect collisions. Maybe someone would like to suggest a better procedure.
Here some code:
[java]
float x = playerPhysicsControl.getPhysicsLocation().x;
float y = playerPhysicsControl.getPhysicsLocation().y;
//Column one is the forward direction.
Vector3f rotationColumn1 = playerPhysicsControl.getPhysicsRotation().getRotationColumn(1);
//Synchronize position of the mouth collision object and the player position.
mouthCollisionObj.setPhysicsLocation(new Vector3f(x + rotationColumn1.x / 2.0f, y + rotationColumn1.y / 2.0f, 0));
[/java]
greetings
getPhysicsRotation now returns a Quaternion, otherwise not much has changed…
EDIT: Maybe someone can help me with that knowledge: When I change the type of the object from GhostControl to RigidBodyControl, “setPhysicsLocation()” starts working properly again.
I’ve been looking for a problem in the code for 2 houres now and I can’t find anything. The only thing that has changed (besides that I’m using the most recent nightly build) is that I’m now in parallel mode and that I use “pSpace.enableDebug(assetManager);” instead of attaching debug shapes. But ghostControl.setPhysicsLocation seems to not work anymore. Every help or suggestion is highly appreciated
Unfortunately I couldn’t solve this problem yet, so I’ve made some executable test code to support you supporting me
[java]
import com.jme3.app.SimpleApplication;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.collision.shapes.BoxCollisionShape;
import com.jme3.bullet.control.GhostControl;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
public class Test extends SimpleApplication {
private BulletAppState bulletAppState;
private Box testBox;
private Geometry testGeom;
private GhostControl ghostControl;
/**
-
@param args
*/
public static void main(String[] args) {
Test app = new Test();
app.setShowSettings(false);
app.start();
}
public void simpleUpdate()
{
ghostControl.setPhysicsLocation(new Vector3f(2.0f, 0.0f, 0.0f));
}
@Override
public void simpleInitApp() {
flyCam.setEnabled(false);
bulletAppState = new BulletAppState();
bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL);
stateManager.attach(bulletAppState);
ghostControl = new GhostControl(new BoxCollisionShape(new Vector3f(0.5f, 0.5f, 0.5f)));
bulletAppState.getPhysicsSpace().enableDebug(assetManager);
bulletAppState.getPhysicsSpace().add(ghostControl);
testBox = new Box(new Vector3f(0.0f, 0.0f, 0.0f), 0.3f, 0.3f, 0.3f);
testGeom = new Geometry(“Box”, testBox);
Material mat = new Material(assetManager, “Common/MatDefs/Misc/SolidColor.j3md”);
mat.setColor(“Color”, ColorRGBA.Red);
testGeom.setMaterial(mat);
testGeom.addControl(ghostControl);
rootNode.attachChild(testGeom);
//Make a test light.
DirectionalLight sun = new DirectionalLight();
sun.setDirection(new Vector3f(2.0f, 0.0f, -1.0f));
rootNode.addLight(sun);
}
}
[/java]
Isn’t the ghostControl now supposed to be on the right-hand side of the box? If not, and someone can tell my why not, I can avoid the mistake I’m making.
greetings
When you attach the Control to a spatial its moved with the Spatial, just use a PhysicsGhostObject or don’t attach the control.
Puh, thank you very much man
Last thing that bothers me now, the debug shape isn’t displayed anymore when I don’t attach the control or when I use a PhysicsGhostObject.
Yeah, only controls have debug shapes.