Check for camera collision

In my demo, I am successfully using the concepts from HelloCollision, as well as HelloPicking.

I am able to make “solid” floors and walls, and am able to check via ray casting if the user picks something.



But, how does one check if the CapsuleCollisionShape collides with an object? I read through the advanced article on collision, and the examples were for collidable objects.



In pseudo code, I need to do the following, but of course, this object doesn’t have access to a collideWith() method. Please advise.



if(casuleCollisionShape.collideWidth(collisionShape)) //or perhaps you would do this with the CharacterControl object?

{

//do something

}





**EDIT: I found this method…I’m thinking that this will need to be used in some way.

characterControl.getCollisionShape()

http://hub.jmonkeyengine.org/forums/?fs=camera+collision

1 Like

For some reason, when a collision occurs, isn’t realized by the collideWith() method. Does my overall setup look okay?





cameraNode = new CameraNode();

For some reason, when a collision occurs, isn’t realized by the collideWith() method. Does my overall setup look okay?





cameraNode = new CameraNode();

Camera camera = new Camera(2,6);

camera.setLocation(player.getPhysicsLocation()); //player = CharacterControl



collidableElevator = new Node();

collidableElevator.attachChild(elevatorSpatial);

collidableElevator.setLocalTranslation(-90f, 80f, -215f);

rootNode.attachChild(collidableElevator);



public void simpleUpdate(float tpf)

{

cameraNode.setLocalTranslation(player.getPhysicsLocation());



CollisionResults results = new CollisionResults();



collidableElevator = new Node();

collidableElevator.attachChild(elevatorSpatial);

collidableElevator.setLocalTranslation(-90f, 80f, -215f);

rootNode.attachChild(collidableElevator);



public void simpleUpdate(float tpf)

{

cameraNode.setLocalTranslation(player.getPhysicsLocation());



CollisionResults results = new CollisionResults();



cameraNode.collideWith(collidableElevator, results);



if (results.size() > 0)

{

collidedWithElevator = true;

}

I don’t see why the cameraNode should have a BoundingVolume in your example. Also you want to go elevator.collideWith() to get all collisions with that.

Actually, you can disregard to camera object with the bounding parameters. I was originally passing this into ChaseCam, but then decided not to use it. All of the rest is still active code.

And still wrong. As said, you a) go terrain.collideWith(player) if you want all collisions with the terrain and b) need some BoundingVolume, an empty Node is an empty Node and will not collide with anything.