My game in jMonkey is the kind that use will have to place objects in a scene (which consist of walls and slabs and floor). All my models are centered at origin. When the user click a point I use ray casting to find the point on the floor where the object will be placed (setLocalTranslation() and shootables.attachChild()).
CollisionResults results = new CollisionResults();
allAttached.collideWith (ray, results);
- Now the problem is that when I click too close to an object or wall, the objects run into each other. I will use physics bounding volume to prevent objects running into each other but how to distinguish between horizontal(floor and slabs) and vertical planes (walls) which are part of same scene model.
I'm using code like this to identify collision in objects
private void checkCollision(Spatial model) {
CollisionResults results = new CollisionResults();
//BoundingBox box = new BoundingBox();
//model.setModelBound(new BoundingBox());
//model.updateModelBound();
BoundingBox box = (BoundingBox) model.getWorldBound();
allAttached.collideWith(box, results);
CollisionResult closest = results.getClosestCollision();
System.out.println("\n SIMAR \n Geometry = ");
System.out.println(closest.getGeometry().getName());
System.out.println("\nContactPoint = " + closest.getContactPoint());
System.out.println("\nContactNormal = " + closest.getContactNormal());
}
}
However the problem is that its not giving me any normals/ etc. Secondly its give me my geom-mall model scene when I shoot floor/ walls and slabs. Using ray casting I can identify horzontal and vertical surface as it gives getContactNormal but in case of BoundingVolume instead of ray, getContactNormal is just null.
How should I identify whether there is a collision with the wall or not.
No comments:
Post a Comment