jPCT - a 3d engine for Java > Support

Wall Collision

(1/1)

AGP:
I'm trying to use the following code. In this case, the walls and the floor are different entities. Collision with the floor is handled separately and works fine. When I do get a collision with the walls, which is not always, I get printouts like "Collided and not with ground. Direction: (-7.939828, -2.0494497) Return route: (5.188492, -2.2546387)." Why would I not at least get the reverse of my direction? How should I do this, instead?

In loop():

--- Code: ---      wallCollision(MOVE_SPEED);
     camera.moveCamera(Camera.CAMERA_MOVEIN, MOVE_SPEED);

--- End code ---


--- Code: ---    private void wallCollision(float MOVE_SPEED) {
SimpleVector cameraZ = camera.getZAxis();
SimpleVector direction = new SimpleVector(cameraZ.x*MOVE_SPEED, cameraZ.y*MOVE_SPEED, cameraZ.z*MOVE_SPEED);
SimpleVector newDirection = collide(direction);
    }
     private SimpleVector collide(SimpleVector directionToHead) {
ground.setVisibility(false);
SimpleVector direction = theWorld.checkCollisionEllipsoid(camera.getPosition(), directionToHead, ELLIPSOID_RADIUS, 5);//.5f, 2f, .5f), 5
if (directionToHead.x != direction.x || directionToHead.z != direction.z) {
     float multiplier = 1f;
     direction.x*= multiplier;
     direction.z*= multiplier;
System.out.println("Collided and not with ground. Direction: ("+directionToHead.x +", "+directionToHead.z +") Return route: ("+direction.x +", "+direction.z +").");
Toolkit.getDefaultToolkit().beep();
     camera.moveCamera(direction, 1f);
}
ground.setVisibility(true);
return direction;
     }

--- End code ---

EgonOlsen:
I'm not sure what you are doing there. You never seem to use corrected direction vector for anything...

AGP:
I did, and you can see it in that code, but I was being thick. I can't help it: if I don't ask for help my brain shuts down. As soon as I get a response I can figure it out. LOL

The following solved it:


--- Code: ---      final float MOVE_SPEED = joystick.getYAxisValue()*(float)deltaTime*-100f;
     SimpleVector direction = wallCollision(MOVE_SPEED);

    private void wallCollision(float MOVE_SPEED) {
SimpleVector cameraZ = camera.getZAxis();
SimpleVector direction = new SimpleVector(cameraZ.x*MOVE_SPEED, cameraZ.y*MOVE_SPEED, cameraZ.z*MOVE_SPEED);theWorld.checkCameraCollisionEllipsoid(camDirection.getZAxis(), ELLIPSOID_RADIUS, MOVE_SPEED, 5);
    }
     private SimpleVector collide(SimpleVector directionToHead) {
ground.setVisibility(false);
SimpleVector direction = theWorld.checkCollisionEllipsoid(camera.getPosition(), directionToHead, ELLIPSOID_RADIUS, 5);//.5f, 2f, .5f), 5
if (directionToHead.x != direction.x || directionToHead.z != direction.z) {
System.out.println("Collided and not with ground. Direction: ("+directionToHead.x +", "+directionToHead.z +") Return route: ("+direction.x +", "+direction.z +").");
Toolkit.getDefaultToolkit().beep();
}
ground.setVisibility(true);
return direction;
     }

--- End code ---

Navigation

[0] Message Index

Go to full version