Collision Detection about the demo car

Started by pangjiale, October 22, 2007, 10:59:38 AM

Previous topic - Next topic

pangjiale


hello, I was reviewing the demo the Car . It is a great work although I cant understand something about the collision.

I had made a  modification on the demo so that the collision would be detected when the car collide with a plant .

unfortunately that dosenot work and the program goes on running .Am I missing something? Thanks in advance.

this is what I have modified on the demo:

Car.java
   public Car() { 
     ...
    setCollisionMode(Object3D.COLLISION_CHECK_SELF|Object3D.COLLISION_CHECK_OTHERS); 
   }

2 BulletPlantListener.java
   
    ...
    public void collision(CollisionEvent e) {
      if (e.getType()==CollisionEvent.TYPE_TARGET && e.getSource()!=null) {
        
          if (e.getSource() instanceof Car) {
             System.out.println("Collide now");    //doesnot happen. sorry        
          }
    }
    ...
    }        

EgonOlsen

IIRC, i'm not using a call to a CollisionEvent-initiating method in the car-demo on the car itself. This means: To trigger the event, you would have to call some checkXXXCollision-Method on the car. Otherwise, the collision won't be noticed. You have to do something similar to the bullets, just with the car. If you are interested in triggering the event only, you can even ignore the result of that method call.

pangjiale

thank you very much.

it works well when I have added moveForward() methord of the Bullet.java into the Car.java