Attaching a Body to another, without the new body impacting the physics of the first in ANY WAY.

Topics: Developer Forum, User Forum
Jan 4, 2014 at 2:32 PM
Basically I want to add a vision / sight cone to an enemy body,

So I have the sight cone body, and enemy body, but every joint or weld I have tried so far has caused the sight cone to severely affect and disrupt the physics and movement of my enemy, most of the time causing the poor guy to go into tailspins.

I only want the sight cone as a sensor, a sensor that has NO physics impact whatsoever on its parent body (the enemy) except simply to stay stuck to it as it moves, matching its position and rotation. but all I can seem to find is weighted attachments, that set up new anchors and whole new physics properties to me new joined body.

I hope you can help.
Jan 4, 2014 at 7:20 PM
Edited Jan 4, 2014 at 7:21 PM
Hi,

you could try this :
coneBody.IgnoreGravity = true;

update()
{
    coneBody.position = enemyBody.position;
    coneBody.rotation= enemyBody.rotation;
}
if the enemy's body and cone's body don't have exactly the same positions and use an offset, replace the first update() line by :
coneBody.position = enemyBody.position + Vector2.Transform(offset, Matrix.CreateRotationZ(enemyBody.rotation));
Hope it'll help you !
Jan 5, 2014 at 10:33 PM
Rather than attaching another body, have you tried creating a sensor fixture?

Something like
            Vertices verts = new FarseerPhysics.Common.Vertices();
            verts.Add(new Vector2(0.0125f, 0.0125f));
            verts.Add(new Vector2(-0.4875f, -0.6375f));
            verts.Add(new Vector2(0.6375f, 0.6375f));
            Shape shape = new PolygonShape(verts, 0f);
            Fixture f = body.CreateFixture(shape);
            f.IsSensor = true;
Giving it a zero density should stop it having an impact on the physics response and setting it as a sensor will prevent collision response.

I've not tested it and you'd obviously need to put your own vectors in to suit your needs but it might be a solution.
Jan 7, 2014 at 9:54 AM
Thanks to both of you.

im going with Domort's suggestion, have just attached the position and rotation to the parent body, and also made it a sensor.

thanks so much guys,