Adding a sensor fixture to a body without affecting movement

Topics: User Forum
Sep 23, 2011 at 5:15 AM

I created a homing projectile that uses a CircleFixture to keep track of nearby entities. Here is a screen capture from my entity editor. The projectile is defined by the magenta polygon.

The homing effect works fine except when I increase the radius of the CircleFixture it slows down the projectile considerably. For example, it moves at approximately half speed when the radius is twice the size. The fixture has a density of 0 and does not modify the mass of the body in any way.  I have checked to ensure that the mass does not change when the fixture is added.  Here's basically what I'm doing in code.

// Creating the body for the projectile
Body body = new Body(world);
List<Vertices> polygons = EarclipDecomposer.ConvexPartition(verts);
FixtureFactory.AttachCompoundPolygon(polygons, density, body); // density is set to 1

// attach sensor CircleFixture
Fixture f = FixtureFactory.AttachCircle(radius, 0, body);
f.IsSensor = true;
f.OnCollision += OnProximitySensorEnter;
f.OnSeparation += OnProximitySensorExit;

// Setting the body to dynamic comes after
projectile.body.BodyType = BodyType.Dynamic;

// apply force in update

I stepped through the creation code and part of the simulation code and couldn't find the cause. Am I doing something wrong or using fixtures incorrectly?

Oct 31, 2011 at 4:51 AM
Edited Oct 31, 2011 at 4:52 AM

Not sure if you've solved this, but I had a similar problem and made the density of the sensor a

very low number like 0.000001f and that seemed to work. Maybe a bug? or maybe someone with more

physics skills can explain why it reacts this way.

Apr 17, 2012 at 3:36 AM

It might just be issues with multiplying and dividing by 0. Not sure. 

Feb 17, 2015 at 2:41 PM
It's an old Post but if someone still needs a

Give the Sensor f the same Velocity as the Projectile body (in Update)

f.Body.LinearVelocity = body.LinearVelocity;

works for me!

Feb 17, 2015 at 8:58 PM
Wow, I was subscribed to this in the off chance someone was able to solve it. I've moved on from XNA to Unity but it's satisfying to know the solution to the problem.