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

One Way Force Field

Topics: Developer Forum
May 17, 2008 at 9:59 AM
The problem: I want to create physics objects in one area, push them out and never let them back in again.  These objects are projectiles that are being shot, but they bounc so I don't want them entering the cannon area because I fear I might create another projectile on top of an existing one. 

Possible Solution: A one way force field (Not sure if it is easily possible though.)

Anybody, have some thoughts?
May 18, 2008 at 10:08 PM
I'd say override it's CollisionHandler to make the geometry collide when the other body is moving in the wrong direction.  This predicate-esque delegate is run every time a contact is made. (Narrow-phase, obviously.)

This is more a job for a broad-phase collision handling delegate, but that doesn't appear to be part of the official code. (Had to add it in myself for my projects.)
May 18, 2008 at 11:05 PM
Edited May 18, 2008 at 11:05 PM
You could also have a geometry for your force field with a certain CollisionGroup.  When you create and fire your projectile give it the same CollisionGroup as the force field. Once the projectile leaves the force field, change it's CollisionGroup so it collides with the force field next time it comes in contact.
May 19, 2008 at 5:57 AM
I was looking into what you mentioned crashlander, and I came across Geom.Collide(Geom) which returns a bool... I would assume this return true if the Geom is Colliding with the specified Geom but I'm getting shaky results.  When they aren't colliding it is randomly flashing true and false, but when they are colliding it is true.  I would post code, but it is so scattered I can't right now.  Maybe I have to make a small test case and make sure it isn't something else.  Or maybe I'm just assuming the function does something it doesn't.
May 20, 2008 at 12:19 PM
I got an email about a bug that may be related to what you're seeing. Try making this fix:

"....However, I found a bug in geom.cs, line 314. The line: "vert = this.worldVertices[i];"
shoul be changed to: "vert = geometry.worldVertices[i];""
May 20, 2008 at 10:14 PM
Yup, that was exactly the issue.  Thanks a lot!