What is the best way to make collision detection for my game?

Hey guys. Can you tell me what is the best way to make collision detection for my game ? Here is a video with my game and how it look now



http://www.youtube.com/watch?v=qUdSvjQpd0Y&feature=youtu.be



I need somehow to test when a bullet with another bullet, player, an enemy or when the player collide with an enemy.

Also, there are different height levels, so, i need somehow to simulate when a bullet from x height level hit a target from y height level even if it does not.

The game will be seen from above.



Thank you.

Pengu.

Can you tell me what is the best way to make collision detection for my game ?


jbullet.

Also, there are different height levels, so, i need somehow to simulate when a bullet from x height level hit a target from y height level even if it does not.


http://hub.jmonkeyengine.org/javadoc/com/jme3/bullet/objects/PhysicsRigidBody.html#setMass(float)

My game day 17


It sounds like a diary xD.

Well, I need to detect the moment when an object collide with another one, not to involve physics forces.

I need a method or something witch return true if two object collide one with another. Like obj1.intersect(obj2). How do i do that?

Yeah thats possible with bullet. Click the documentation link above :roll:

Look, i’ve tried but i don’t know why doesn’t work…can you help me?



[java]

import com.jme3.app.SimpleApplication;

import com.jme3.bullet.BulletAppState;

import com.jme3.bullet.collision.PhysicsCollisionEvent;

import com.jme3.bullet.collision.PhysicsCollisionListener;

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

import com.jme3.bullet.control.RigidBodyControl;

import com.jme3.bullet.util.CollisionShapeFactory;

import com.jme3.input.KeyInput;

import com.jme3.input.controls.AnalogListener;

import com.jme3.input.controls.KeyTrigger;

import com.jme3.light.AmbientLight;

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.Node;

import com.jme3.scene.shape.Box;





public class TestCollision extends SimpleApplication implements AnalogListener,PhysicsCollisionListener

{

private Node cube1, cube2;

private BulletAppState bulletAppState;

private RigidBodyControl controlCube1, controlCube2;

public static void main(String args[])

{

TestCollision testCollision=new TestCollision();

testCollision.start();

}

@Override

public void simpleInitApp()

{

AmbientLight al=new AmbientLight();

al.setColor(ColorRGBA.White);

rootNode.addLight(al);

DirectionalLight dl=new DirectionalLight();

dl.setDirection(new Vector3f(0, -1, -2));

flyCam.setMoveSpeed(10);

Geometry cube1=makeBox(new Vector3f(1, 0, 1));

Geometry cube2=makeBox(new Vector3f(-2, 0, -2));

this.cube1=new Node(“cube1”);

this.cube2=new Node(“cube2”);

this.cube1.attachChild(cube1);

this.cube2.attachChild(cube2);

rootNode.attachChild(this.cube1);

rootNode.attachChild(this.cube2);

initKeys();



bulletAppState=new BulletAppState();

stateManager.attach(bulletAppState);

bulletAppState.getPhysicsSpace().addCollisionListener(this);

bulletAppState.getPhysicsSpace().enableDebug(assetManager);

initControl(controlCube1, this.cube1);

initControl(controlCube2, this.cube2);

}

private Geometry makeBox(Vector3f loc)

{

Box box=new Box(loc, 0.5f, 0.5f, 0.5f);

Geometry cube=new Geometry(“Cube”, box);

Material matLightning=new Material(assetManager, “Common/MatDefs/Light/Lighting.j3md”);

cube.setMaterial(matLightning);

return cube;

}

private void initKeys()

{

inputManager.addMapping(“left”, new KeyTrigger(KeyInput.KEY_NUMPAD4));

inputManager.addMapping(“right”, new KeyTrigger(KeyInput.KEY_NUMPAD6));

inputManager.addMapping(“forward”, new KeyTrigger(KeyInput.KEY_NUMPAD8));

inputManager.addMapping(“back”, new KeyTrigger(KeyInput.KEY_NUMPAD5));



inputManager.addListener(this, new String[]{“left”,“right”,“forward”,“back”});

}

@Override

public void onAnalog(String name, float value, float tpf)

{

final float SPEED=2;

if(name.equals(“left”))

{

cube1.move(-SPEEDtpf, 0, 0);

}

if(name.equals(“right”))

{

cube1.move(SPEED
tpf, 0, 0);

}

if(name.equals(“forward”))

{

cube1.move(0, 0, -SPEEDtpf);

}

if(name.equals(“back”))

{

cube1.move(0, 0, SPEED
tpf);

}

}

@Override

public void collision(PhysicsCollisionEvent e)

{

System.out.println(“cube 1 intersect cube 2”);

}

private void initControl(RigidBodyControl control, Node cube)

{

CollisionShape collisionShape=CollisionShapeFactory.createDynamicMeshShape(cube);

control=new RigidBodyControl(collisionShape, 0);

cube.addControl(control);

bulletAppState.getPhysicsSpace().add(control);

}

}

[/java]

Click →



Read →

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:beginner:hello_picking

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:beginner:hello_collision

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:beginner:hello_physics

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:collision_and_intersection

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:mouse_picking

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:physics

tnx…