Using isSensor with OnCollision

Topics: Developer Forum, User Forum
Dec 2, 2008 at 10:57 PM
Hello,
I'm still kind of noob with using the farseer, but have gotten the basics down so far, but I've come up with a problem...

I'm trying to use objects as sensors, and then listening to the OnCollision event. So, I have a collision group of sensors (implicitly static), and a collision group of objects which move around. It's working well, except for when two sensors overlap, and a object is in the overlap zone. Only one of sensors recognize the object, not both. Am I messing something up on using the OnCollision? Or when three or more objects overlap, does it only create an arbiter for two of them? Or a separate arbiter for each combination?

Thank you so much for any help in advance.
Coordinator
Dec 2, 2008 at 11:01 PM
Sensors are regular physics objects. But they are static (as you wrote) and does not respond to collision respones (impulses calculated from an impact).
They should both report a collision even if they overlap. Static bodies does not collide as they can't move, so overlapping sensors should not be any different than non-overlapping ones.

Make sure to test both geometries returned in the OnCollision method (the one you registered with the OnCollision delegate)
It may very well be here you are losing your object. Try it out.
Dec 2, 2008 at 11:18 PM
Wow, thanks for the fast response :)

Hmm, well I noticed that sometimes it varies between geom1 being the sensor and geom1 being the moving object.
So, so far it's just been testing geom1.oncollision, then when geom2.oncollision happens, that oncollision is firing a different function, the oncollision for the moving object, which currently isn't doing the same logic.

Perhaps having one master OnCollision function which all objects link to would be better than having separate ones for different objects, that way, when the second geom.oncollision fires, it will still do the same thing.




Dec 3, 2008 at 10:37 PM
Alright, I got it working now in the games current release.

I basically wrote a function that can handle every possibility, and every geom.OnColllison is += GenericCollisionFunction

So right now, lets say I have 5 different types of object in the game, it
will switch through the first geom type, then switch through the second geom type.

Here's the psuedo code for anyone interested

I've added a container type ID enum to every geom, as I have several different pools
I've added a node ID to every geom, as the pools have indexing.
Every geom is part of a generic physics object, which is part of a specialized unit object, which contains custom values such as damage etc.

OnCollision(geom1, geom2, contactlist)

retrieve the unit from the respected unit pool using geom1 container id and node id
retrieve the unit from the respected unit pool using geom2 container id and node id

go through the different types of containers for geom1, landing on the current one

switch (geom1.containerID)

the container ID is an enum

containerid.unit pool 1

go through the different types of containers for geom2, landing on the current one
switch (geom2.containerID)

apply logic
return
repeat, etc

I have the concrete example in my game, in the Utility.cs

Hope my psuedocode helps anyone else with implementing Farseer Physics :)