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

Joint for sensor body

Topics: Developer Forum
Nov 9, 2012 at 4:51 AM

I have a sensor (dynamic weightless body) which I would like to attach to a character (dynamic body). Which joint would be appropriate to attach the sensor to the character? I've tried the weld joint, but it stops the character from rotating for some reason. I've tried the distance joint, but it causes the character to behave in ways which it would not if it had not been attached to the sensor. I need a joint that causes the sensor to always be at the position of the character but does not affect the character's movement in any way. I realize that I could have just attached a sensor fixture to the character but for reasons I will not go into, this is not an option.

Nov 9, 2012 at 2:06 PM

I'd say that there are certainly better ways to achieve what you need but without much info..You evidently need some form of a spatial query but for that you don't need an actual body at all - you can use AABBs or raycasting or point-in-polygon testing or other things.

Anyway here goes a suggestion for the original request:

Make the "sensor" body with very low density (mass). Attach it with a weld joint. Subscribe to its BeginContact and cancel all collisions so it behaves like a real sensor. Might work as a workaround against a simple sensor fixture that has those things built-in.

Nov 9, 2012 at 7:44 PM

body.IsSensor already has that built in (gives collision info but does not react to collisions). My issue is with the weld joint which does not allow the character to rotate after being attached. I'm most likely just going to create a custom joint after already testing the existing ones.

Nov 10, 2012 at 12:36 AM

Why shouldn't the weld joint allow the attached body to rotate? I have not seen anything like that in my experience and I use weld joints a lot . Are you sure you don't have a mass problem ("sensor" body is too heavy) or it's set to FixedRotation=true or it collides with the world so it hampers free movement of the attached body.

Nov 10, 2012 at 12:51 AM

I have tried setting the sensor body to have  a mass of 0 and 0.000001f, so it shouldn't be a mass problem. Both bodies have FixedRotation=false. The sensor body is a sensor so any collisions do not physically affect it.

Nov 10, 2012 at 1:42 AM

I tried this simple TestBed case to check and don't see any issues related to rotations. Hope it could be useful.

using FarseerPhysics.Dynamics;
using FarseerPhysics.Dynamics.Joints;
using FarseerPhysics.Factories;
using FarseerPhysics.TestBed.Framework;
using Microsoft.Xna.Framework;

namespace FarseerPhysics.TestBed.Tests {
	public class WeldSensorTest:Test {
		private WeldSensorTest() {
			World.Gravity = Vector2.Zero;
			var ground = BodyFactory.CreateEdge(World, new Vector2(-10, 0), new Vector2(10, 0));
			//Create a rectangular character at 0,5
			Body character = BodyFactory.CreateRectangle(World, 5, 5, 1, new Vector2(0, 5));
			character.BodyType = BodyType.Dynamic;
			//Create a circular sensor body  and attach it to the upper right corner
			Body sensor = BodyFactory.CreateCircle(World, 2, 1, character.GetWorldPoint(new Vector2(2.5f, 2.5f)));
			sensor.BodyType = BodyType.Dynamic;
			sensor.IsSensor = true;
			//Weld them as they are
			var wj = new WeldJoint(character, sensor, character.GetLocalPoint(sensor.Position), Vector2.Zero);
		internal static Test Create() {
			return new WeldSensorTest();

Nov 10, 2012 at 1:46 AM

I have a circular character, circular sensor, and move via linear impulses (ground and character have high friction). It works fine with other joints except weld.