Author Topic: Collision Detection about the demo car  (Read 3341 times)

Offline pangjiale

  • byte
  • *
  • Posts: 2
    • View Profile
Collision Detection about the demo car
« on: October 22, 2007, 10:59:38 am »

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:

1  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        
          }
    }
    ...
    }        

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Collision Detection about the demo car
« Reply #1 on: October 22, 2007, 04:30:30 pm »
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.

Offline pangjiale

  • byte
  • *
  • Posts: 2
    • View Profile
Re: Collision Detection about the demo car
« Reply #2 on: October 23, 2007, 03:19:01 am »
thank you very much.

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