how to know the target of a collision.

Started by Melssj5, May 12, 2008, 07:34:04 PM

Previous topic - Next topic

Melssj5

Hi, I want to know the target of a collision but the CollisionEvent only has getSource () and getObject () that are the same object inmost cases, but a method getTarget () is missing. Is there any way to get the target of a collision is my CollisionListener is on the source of the collision.....?  >:(

I want to put the collisionListener on the bullets to be fired and when they collide with something do something, but on this situation theObject and getSource returns the same object that is the bullet.
Nada por ahora

EgonOlsen

You have to add the listener to the target, not to the source to get it. getSource() always returns you the source, while getObject() returns the object that has caused the event, i.e. the object to which the listener has been added.

Melssj5

Wouldnt be better to add the getTarget method????

My first idea was to add the collisionListener to the target but I am having problems trying to transfer it. I guess that adding the method would be a great idea to make it more adaptable to other situations.
Nada por ahora

EgonOlsen

#3
No, because a collision has one source but can have multiple targets. But one target has only one collision source. That's why it is the way it is.
In your case, why don't you want to add the listener to the target instead? What's the problem in transfering it?

Melssj5

a notSerializable exception if I add the listener before transfering it and if I try to add the listener after transfering I am receiving an optionalDataException.
Nada por ahora

EgonOlsen

But after all, it's just an interface. If your implementation isn't serializable, it's not the interface's fault. It has to be something in your listener that can't be serialized correctly. Maybe the complete stack trace would help to find the problem.
About the other exception: I don't see how adding the listener could cause this. It's an exception that is thrown on reading in the serialized object, so i guess it happens on the server? Are you 100% sure that server and client are using the same set of classes?