Author Topic: collision detection (source and target)  (Read 6630 times)

Offline dmouse

  • byte
  • *
  • Posts: 17
    • View Profile
collision detection (source and target)
« on: August 24, 2008, 09:27:54 pm »
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.


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: collision detection (source and target)
« Reply #1 on: August 24, 2008, 10:40:05 pm »
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.

Offline dmouse

  • byte
  • *
  • Posts: 17
    • View Profile
Re: collision detection (source and target)
« Reply #2 on: August 25, 2008, 12:17:06 am »
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.

Offline Melssj5

  • double
  • *****
  • Posts: 724
    • View Profile
Re: collision detection (source and target)
« Reply #3 on: August 25, 2008, 05:50:25 pm »
I am runnig into the same problem. Anyway FlierMatch is dead!
Nada por ahora

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: collision detection (source and target)
« Reply #4 on: August 26, 2008, 12:10:09 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)?

Offline Melssj5

  • double
  • *****
  • Posts: 724
    • View Profile
Re: collision detection (source and target)
« Reply #5 on: August 26, 2008, 12:23:14 am »
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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: collision detection (source and target)
« Reply #6 on: August 26, 2008, 12:27:42 am »
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.

Offline Melssj5

  • double
  • *****
  • Posts: 724
    • View Profile
Re: collision detection (source and target)
« Reply #7 on: August 26, 2008, 12:42:48 am »
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

Offline dmouse

  • byte
  • *
  • Posts: 17
    • View Profile
Re: collision detection (source and target)
« Reply #8 on: August 27, 2008, 12:30:24 pm »
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.

Offline ramzes0071

  • byte
  • *
  • Posts: 11
    • View Profile
Re: collision detection (source and target)
« Reply #9 on: November 11, 2013, 10:37:37 pm »
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: collision detection (source and target)
« Reply #10 on: November 11, 2013, 11:03:46 pm »
Are you sure that you haven't add it multiple times?

Offline ramzes0071

  • byte
  • *
  • Posts: 11
    • View Profile
Re: collision detection (source and target)
« Reply #11 on: November 12, 2013, 10:21:13 am »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: collision detection (source and target)
« Reply #12 on: November 12, 2013, 11:01:28 am »
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.