www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: xNaXDy on May 27, 2012, 10:54:49 pm

Title: Calculate collision for specific objects?
Post by: xNaXDy 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?
Title: Re: Calculate collision for specific objects?
Post by: EgonOlsen 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) (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.
Title: Re: Calculate collision for specific objects?
Post by: xNaXDy 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?
Title: Re: Calculate collision for specific objects?
Post by: vickt 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.