Author Topic: Calculate collision for specific objects?  (Read 1026 times)

Offline xNaXDy

  • byte
  • *
  • Posts: 7
    • View Profile
Calculate collision for specific objects?
« on: May 27, 2012, 10:54:49 pm »
Basically I need a function that allows me to calculate if my 'player' is colliding with any of the 'enemies'. The function must NOT be called when 'player' collides with 'block' for example.

Do you know how to accomplish this?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Calculate collision for specific objects?
« Reply #1 on: May 28, 2012, 08:51:11 pm »
You can make all these objects (enemy, block...) collision aware (http://www.jpct.net/doc/com/threed/jpct/Object3D.html#setCollisionMode(int)) and add an implementation of the CollisionListener interface to your enemies. When using the build-in collision methods, the interface's collision()-method will be called if anything collides with the enemy.

Offline xNaXDy

  • byte
  • *
  • Posts: 7
    • View Profile
Re: Calculate collision for specific objects?
« Reply #2 on: May 30, 2012, 12:28:09 am »
I don't quite get the thing with check_self and check_others. Also what would I have to do if there was like 19 different types of enemies?

Offline vickt

  • byte
  • *
  • Posts: 9
    • View Profile
Re: Calculate collision for specific objects?
« Reply #3 on: May 30, 2012, 02:17:20 am »
check_self lets other objects collide with the object, check_others lets that object collide with others. You can use the | to combine them.

After finding the object ID with one of the collision methods, you can compare it to a list of your Enemy and Block's object IDs.