This project has moved and is read-only. For the latest updates, please go here.

How can i make a geom that will not collide with anything? (SOLVED)

Jan 30, 2009 at 5:45 PM
I' slowly getting the hang of everything am but am still needing a little help.
I right now I have one body connected to two  geoms. The one geom Im happy with, but want to make the second geom not collide with anything in the scene yet still pick up if it interests with any other object.
what is the best way to approach this?
Jan 30, 2009 at 5:49 PM
There is a CollisionEnabled property in the Geom class. If you disable it, the geometry will not be included in the broad phase collision test and thus will not collide with anything.
You can still use Geom.Collide() on the geometry to check manually if it collides with something (or intersect with something).
Jan 30, 2009 at 5:56 PM
genbox you're a true hero..

on behalf of all farseer users
Jan 30, 2009 at 8:05 PM
Edited Jan 30, 2009 at 10:01 PM
i tried out your solution but as from what i understand is that Geom.Collide() only checks for collision with a specific point. Is there a way to check for collision (or intersection) with all objects in the scene? similar to..
        bool OnCollision(Geom geom1, Geom geom2, ContactList list)  
            return true;
(this hasn't been working when i turned off 'CollisionEnabled'?)

Just to be clear with my questions. Imagine a circle character is on the screen surrounded by multiple other collision objects(for instance squares). The player controls the direction the circle is moving as it bounces of the squares. What i want is for this circle to have a force field around it that is larger then the actual circle itself, but always in the same position. This force field can go through any objects without bouncing of them. What I'm trying to achieve is weather on not that force field is penetrating any of the "squares" and what part is being penetrated(or the direction the penetration is coming from relative to the circle).

(edit 2)
isSensored might be a solution.. problem is that it keeps static which prevents the body from moving.
Jan 31, 2009 at 12:43 AM
The OnCollision event won't work with CollisionEnabled set to false. It does not check for collision automatically, but you are still able to check for collisions manually by calling Geom.Collide() on it.

If you want to check collisions with all other objects on the scene, you need to have a list of objects added to the game and iterate it with a loop. Inside the loop you use Geom.Collide(sceneObject).
As for the sensor objects, they are actually just static object (nonmovable) and does not react to collisions. Geometries have a CollisionResponseEnabled property that tells the geometry to NOT react to a collision from other geometries. This might be what you are looking for.
Jan 31, 2009 at 3:34 PM
Edited Jan 31, 2009 at 3:35 PM
What i did up to now is make two separate bodies that each contain a separate geom.
The smaller "Player" geom is the actual object and the larger one is the invisible "ForceField".
I set the ForceFieldGeom to be in the same collision group as the Player object, so they don't collide with each other
and evey frame i repositioned the ForceField so it will be directly ontop of the 'Player's position.
This worked great for static object when it came to collision detection, but as i suspected would deflect all
non static objects.
I then set the isSensor to true for the forcefield and now the collsion detection between the Player and non static object is working great.
the problem is that it's not detecting static objects?

Is there a way to get best of both worlds, so that i collision detect static and non-static objects.
Or is the only solution to ditch the OnCollision detection and use Geom.Collide()?
btw: I'm using OnCollision for the collision detection.

Jan 31, 2009 at 3:40 PM
Sensor geometries has IsStatic set to true, and by definition you can't collide two static geometries (they can't move... they can't collide).

Did you have a look at the CollisionResponseEnabled property in the Geom class? It's just like a sensor, but it's not static which means it will collide with both static and nonstatic objects.
Jan 31, 2009 at 3:46 PM
Edited Jan 31, 2009 at 3:48 PM
i might not be familiar with how to use it, but if i replace the "ForceField.isSensor = true" with "ForceField.CollisionResponseEnabled = true" then I don't see much of a difference between that and it being off. Non static object are deflected(is the main concern).

(edit) O wait!!!!!!  ForceField.CollisionResponseEnabled = false (not true).... Works Sweet!!! thanks for the help.
Jan 31, 2009 at 3:57 PM
Edited Jan 31, 2009 at 3:57 PM
Oh, I think I had my own version of what you wanted in my head. Sorry about that.

If your forcefield should not interact with any objects at all, you can just disable collision for it. But I would think that you would want some objects to collide with it, like bullets.
You could solve this by making your own checks. You have noticed that the OnCollision method needs a boolean returned right? if you return true, the collision will happen, but if you return false, it will not get registered and no overhead will occur. (performance wise).
Use the Tag property of the geometry to carry the sceneobjects you have.

Just make something like this inside the OnCollision method:

private bool OnCollision(Geom geom1, Geom geom2, ContactList list)
    SceneObject sceneObject = geom1.Tag as SceneObject;
    if (sceneObject != null)
        //If the geometry is a sceneobject of type bullet, make the collision happen. (Bullets bounce off the forcefield)
        return (sceneObject.Type == SceneTypes.Bullet)

// Make the collision happen by default.
return true;

Edit: Oh, and make sure to test geom2 as well.
Jan 31, 2009 at 4:51 PM
Edited Jan 31, 2009 at 4:58 PM
everything is working great!.. thanks so much for your time genbox..
Maybe you might also have a solution for my last problem..

Is there a way i can detect with my ForceField which direction the collision is coming from. So lets say there is a Bullet heading its way can i detect if its coming from the top right? or top left? or maybe just from the left or bottom? keep in mind im using OnCollsion for my collision detection.
Jan 31, 2009 at 6:01 PM
I'll answer in your other thread: