Collision detection between 2 boxes

hi at all…

Somebody can help me how manage a collision detection of 2 boxes?

i try to follow hello collision tutorial but i don’t understand how to make collision.

thanks :wink:

Sorry to be so blunt, but what are you expecting to get out of a question like this? Should someone simply whip up a new, alternative tutorial, hoping that you’ll understand it this time?



My point is, you’re already stretching it by asking the supporters to reiterate something that’s already explained in the tutorial, so the least you can do is explain how far you got into the tutorial, which parts you get and which ones you don’t and most importantly what you’ve tried so far. It’s a lot easier to help you out if you can explain your trail of thought.

ok sorry…i try to understand by mysel.

thanks.

bisciasia said:
ok sorry..i try to understand by mysel.
thanks.

Ehm, that's not what I meant mate. If you really can't understand the tutorial, people are willing to help, and there might even be something about the tutorial we should consider changing so it's more easily understood. What you need to do if you can't understand the tutorial is to explain exactly what kind of problems you are having with it.

ok… now i try again to implement collision and if i dont understand i post here my problem.

thanks :wink:

For understand collisions in jmonkey i followed tuttorial hello collision.

i have some problems with physics of objects.

i created 2 boxes and i want that they fall down according the gravity.

with 2 boxes i get a strange movement of boxes but if i putonly a box in my code all works great. :wink:

Can you help me? thanks.





the code :

[java]package mygame;



import com.jme3.app.SimpleApplication;

import com.jme3.bullet.BulletAppState;

import com.jme3.bullet.control.RigidBodyControl;

import com.jme3.bullet.util.CollisionShapeFactory;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Quaternion;

import com.jme3.math.Vector3f;

import com.jme3.renderer.RenderManager;

import com.jme3.scene.Geometry;

import com.jme3.scene.shape.Box;





public class Main extends SimpleApplication {



public static void main(String[] args) {

Main app = new Main();

app.start();

}

Geometry geom;

Geometry geom2;

BulletAppState bastate;



@Override

public void simpleInitApp() {



//create 2 boxes

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

geom = new Geometry("Box", b);

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

mat.setColor("m_Color", ColorRGBA.Blue);

geom.setMaterial(mat);



Box b2 = new Box(new Vector3f(1,1,1), 1, 1, 1);

geom2 = new Geometry("Box2", b2);

Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");

mat2.setColor("m_Color", ColorRGBA.Orange);

geom2.setMaterial(mat2);



//add geometry on rootNode

rootNode.attachChild(geom);

rootNode.attachChild(geom2);



//create and attach BulletAppState object

bastate = new BulletAppState();

stateManager.attach(bastate);



//create a rigidbodycontrol for 2 boxes

RigidBodyControl myControl=new RigidBodyControl( CollisionShapeFactory.createBoxShape(geom) , 1.0f );

RigidBodyControl myControl2=new RigidBodyControl( CollisionShapeFactory.createBoxShape(geom2) , 1.0f );



//add a rigidboycontrol to geometry of boxes

geom.addControl(myControl);

geom2.addControl(myControl2);



//add rigidbodycontrols to physicsspace

bastate.getPhysicsSpace().add(myControl);

bastate.getPhysicsSpace().add(myControl2);



//specifications of Physics

bastate.getPhysicsSpace().setGravity(new Vector3f(0f,-4f,0f));

bastate.getPhysicsSpace().setAccuracy(0.005f);



//add geometry on physics space

bastate.getPhysicsSpace().add(geom);

bastate.getPhysicsSpace().add(geom2);





}



@Override

public void simpleUpdate(float tpf) {



}



}

[/java]



in my code if b2 (with its geometry and other objects) is deleted,all works but i dont understand why with 2 boxes i get wrongs movements. :wink:

The location of the mesh of box 1 is off. This will be used for the physics too, use physicsSpace.enableDebug(); to show the collision shapes, then it should be clear.

sorry but i don’t unsderstand :frowning: bastate.getPhysicsSpace().enableDebug() doesn’t exist :frowning:

i solved my problem by creating 2 BulletAppState object,one for each box.

now all works but is this a correct solution?

thanks.

Update to latest svn, the exact method signature is

[java]public void enableDebug(AssetManager manager) [/java]

Your solution is not correct, no.

ok but in which class is this method? if i know this class i check if method exist else i update my code.

http://hub.jmonkeyengine.org/javadoc/com/jme3/bullet/PhysicsSpace.html#enableDebug(com.jme3.asset.AssetManager)

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

ok. i dont have this method in my class. but i dont understand why. i downloaded jmonkey platform 3 alpha.

this platform doesnt contains ultimate version of codes?

can i find last version alredy build or i have to download code by google code through svn?

thanks for replyes.

When you are using RigidBodyControl you are definitely not using alpha-3 but some nightly version after.

ok i updated my code. now i try to use this function. thanks a lot for now :wink: