Author Topic: Wall Collision  (Read 2068 times)

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Wall Collision
« on: August 12, 2017, 12:10:26 am »
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: [Select]
     wallCollision(MOVE_SPEED);
     camera.moveCamera(Camera.CAMERA_MOVEIN, MOVE_SPEED);

Code: [Select]
    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;
     }

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Wall Collision
« Reply #1 on: August 13, 2017, 06:23:52 pm »
I'm not sure what you are doing there. You never seem to use corrected direction vector for anything...

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Wall Collision
« Reply #2 on: August 13, 2017, 10:33:04 pm »
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: [Select]
     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;
     }
« Last Edit: August 14, 2017, 05:45:18 am by AGP »