collision detection (source and target)

Started by dmouse, August 24, 2008, 09:27:54 PM

Previous topic - Next topic

dmouse

Hi,

I was wondering if there was perhaps a way to use something like Object3D.checkForCollisionSpherical(SimpleVector translation, float radius)) but to have access to information about which Object3D(s) were hit (if any) as a result of the translation in question.

I have also experimented with CollisionListener.collision(), but since this needs to run in it's own thread, I can't really use it.

Ideally, I would like a method by which I could check if 2 objects are currently overlapping or are about to collide as a result of a translation. I could then use this method to selectively detect collisions between objects at will.

Is there any way of doing this in jPCT?

Any help would be appreciated.

Thanks in advance.


EgonOlsen

The CollisionListener should be the way to go. Why can't you use it? What does have to run in its own thread in your case? jPCT isn't thread safe...in either way you'll run into problems when you are manipulating objects in one thread while checking for collisions in another.

dmouse

After more experimentation, it seems that my problems with CollisionListener.collision() were not thread related, but were in fact caused by the collision method sometimes being notified twice with regards to the same collision event. This means that I was sometimes executing response logic twice for the same collision event (once each time it was notified), producing unpredictable results.

I seem to have worked around this by, placing all collision event notifications into a queue, and then removing duplicate entries from the queue, before finally executing responses for the collision events left in the queue. This produces predictable and expected results.

I am not sure if I was doing something wrong with CollisionListener.collision(), is there a reason why it might get notified multiple times for the same collision event?

Thanks in advance.

Melssj5

I am runnig into the same problem. Anyway FlierMatch is dead!
Nada por ahora

EgonOlsen

Quote from: dmouse on August 25, 2008, 12:17:06 AM
I am not sure if I was doing something wrong with CollisionListener.collision(), is there a reason why it might get notified multiple times for the same collision event?
That should not happen and i've never ever experienced it albeit i'm using CollisionListeners a lot. Are you sure that the event is 100% the same (i.e. same source, same target, same algorithm)?

Melssj5

for example lets say my ship has a collisionListener added, when I crash my ship against a mountain the it generates 2 events.

The mountain colliding with the ship and viceversa.

in both cases the source is the ship.
Nada por ahora

EgonOlsen

Ok, but that is intentionally. If you add the listener to both, you'll get the event twice. I usually add it to the target only.

Melssj5

I dont remember if I have the listener in both objects but surely that it sounds logic that if two listened objects collide then it will generate 2 events but it will be much better if a collisions generates just one event with a getTarget and getSource methods, but you told me the other day that a source may have multiple targets, then it would be better to return an array of targets from one source in one collision.
Nada por ahora

dmouse

Quote from: EgonOlsen on August 26, 2008, 12:10:09 AM
Quote from: dmouse on August 25, 2008, 12:17:06 AM
I am not sure if I was doing something wrong with CollisionListener.collision(), is there a reason why it might get notified multiple times for the same collision event?
That should not happen and i've never ever experienced it albeit i'm using CollisionListeners a lot. Are you sure that the event is 100% the same (i.e. same source, same target, same algorithm)?

I think I realized what the problem was. When the game was re-initialized I was adding CollisionListeners to all the game entities _again_ (this had already happened during the first initialization). Removing this fixed the problem, collisions are only notified once now, and I no longer have to process them in a queue etc..

Thanks for your help.

ramzes0071

Hi,
I have the same problem. I have added collision listener to one object, but the same event is called twice. How it can be solved?

EgonOlsen

Are you sure that you haven't add it multiple times?

ramzes0071

I'm sure. Maybe this is a bug in the engine. Earlier, someone suggested a solution of queuing events. Do you know how to use it.

EgonOlsen

As mentioned above, i don't think that this is an engine bug. The events are triggered once the collision detection is done and that only happens once per call, because it's the last part of that method and there's no actual way that i can see to call this twice. In addition, i've never experienced this behaviour and i'm using the listeners a lot.
If possible, try to reproduce the problem in a test case and i can have a look at it.