Author Topic: collision detection  (Read 1839 times)

Offline KOsmos

  • byte
  • *
  • Posts: 4
    • View Profile
collision detection
« on: May 19, 2009, 11:46:26 pm »
Hi

I can't apply any of the collision detection methods.

I have 3 Objects:

Code: [Select]
//a floor
terrain = Primitives.getPlane(30, 60);
terrain.setTexture("rocks");
terrain.rotateX((float)Math.toRadians(90));

//wall
wall = Primitives.getBox(10, 15);
wall.translate(-400,0,0);
wall.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS|Object3D.COLLISION_CHECK_SELF);
wall.setCollisionOptimization(Object3D.COLLISION_DETECTION_OPTIMIZED);

//player
public Player(){
       super(Primitives.getSphere(30));
       this.translate(0, -30, 0);
       this.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS | Object3D.COLLISION_CHECK_SELF);
       this.setCollisionOptimization(Object3D.COLLISION_DETECTION_OPTIMIZED);
}

public void moveForward(){
        int objID=checkForCollision(getZAxis(), getSpeed());
        if (objID==Object3D.NO_OBJECT) {
           super.moveForward();
        }
}

I move the player(ball) as in the car example. I want to perform a collision check against the wall. What am I missing?

Edit:
It actually works, but when the wall is a plane and not a box. Why can't I apply this method to a box?
« Last Edit: May 20, 2009, 12:40:45 am by KOsmos »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: collision detection
« Reply #1 on: May 20, 2009, 03:25:14 pm »

Offline KOsmos

  • byte
  • *
  • Posts: 4
    • View Profile
Re: collision detection
« Reply #2 on: May 20, 2009, 10:54:11 pm »
That solved my problem. Thank You.