CollisionShapes, need advice

Hi,

I’m having a little bit of an issue creating proper collision shapes and if possible would like some advice on the issue.

Issue:
When ever i try to attach a simple HullCollisionShape with a cylinder mesh, the orientation of the shape is always different from an imported cylinder model. For example if the imported cylinder model was sitting flat on a plane the collision shape would be on its side.

Attempted:
–Creating custom dynamic shapes from the spatial using the the CollisionShapeFactory class <-- Seem to phase through other objects
–Rotating the shapes/imported object in blender/program/sdk
–Tried this configuration : Node --> 1. imported object 2.RigidBodyControl and then orienting them, no luck

Would like to know if im just going about it wrong, or im missing something from the tutorials or book.

Experience : less than two weeks.

Thank you in advance.

Did you apply location rotation and scale to your model before you exported it?

Originally the cylinder object was sitting on the plane on it’s bottom side. Then i tried rotating it in blender and exported it again, which did not fix the issue.

Look at Apply Transformations here: http://wiki.blender.org/index.php/User:Fade/Doc:2.6/Manual/3D_interaction/Transform_Control/Reset_Object_Transformations

@constantine said: Look at Apply Transformations here: http://wiki.blender.org/index.php/User:Fade/Doc:2.6/Manual/3D_interaction/Transform_Control/Reset_Object_Transformations

Thank you that did the trick.

Since I was looking for this, maybe others are also looking for this. Here is how I have it setup now.
*Note the plane does not have the fix that constantine speaks of, and that is why the imported model and the collision shape are not aligned properly.

Blender Image of the imported simple models:

Program image of the models with RigidBodyControls attached:

*Cylinder is correctly configured in blender
**Plane is not correctly configured in blender

And program code:
[java]
public class PhysicsTest extends SimpleApplication {

@Override public void simpleInitApp(){
	
	//Camera
	flyCam.setMoveSpeed(20f);
	
	//App state
	SimpleAppState appState = new SimpleAppState();
	stateManager.attach(appState);
}

@Override public void simpleUpdate(float tpf){
	
}

public static void main(String[] args){
	PhysicsTest app = new PhysicsTest();
	app.start();
}

class SimpleAppState extends AbstractAppState {
	
	AmbientLight ambient;
	DirectionalLight directional;
	
	BulletAppState bulletState;
	
	Node scene;
	
	public SimpleAppState(){
		bulletState = new BulletAppState(new Vector3f(-20, -20, -20), new Vector3f(20, 20, 20));
		directional = LightingGenerator.getSimpleDirectionalLight();
		ambient = LightingGenerator.getSimpleAmbientLight();
	}
	
	@Override public void initialize(AppStateManager stateManager, Application app){
		super.initialize(stateManager, app);
		stateManager.attach(bulletState);
		
		//Load model
		scene = (Node) assetManager.loadModel("prototype-game/test/test.scene");
		scene.setMaterial(MaterialGenerator.getSimpleLightMaterial(assetManager));

		//Physics
		initPhysics();
		
		//Attach
		rootNode.attachChild(scene);
		rootNode.addLight(directional);
	}
	
	@Override public void update(float tpf){
		bulletState.setDebugEnabled(true);
	}
	
	private void initPhysics(){
		for(Spatial e : scene.getChildren()){
			if(e.getName().equals("coin")){
				Cylinder mesh = new Cylinder(10, 10, 1, 1, true);
				e.setLocalTranslation(e.getLocalTranslation().add(new Vector3f(0, 2, 0)));
				e.addControl(new RigidBodyControl(new HullCollisionShape(mesh), 0f));
			}else if(e.getName().equals("plane")){
				Quad mesh = new Quad(1, 1);
				e.addControl(new RigidBodyControl(new HullCollisionShape(mesh), 0f));
			}
			bulletState.getPhysicsSpace().add(e);
		}			
	}
	
}

}
[/java]

1 Like