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

Rotating a sensor by a different origin? - SOLVED

Apr 15, 2010 at 1:48 PM
Edited Apr 15, 2010 at 1:49 PM

My towers (towerdefense game) consist of 2 parts: the tower's body itself (the red square) and a sensor (that triggers the bullet when an enemy walks over it). The sensor at 0 degrees is the blue one, 45 degrees is the green one and 90 degrees is the yellow one (it ranges between 0-359 degrees).

After the player positions the tower he can rotate the tower. I calculate the angle between te mouse and the body's origin and that gives me the rotation angle. However, when I rotate the sensor the following happens:

The orange sensor (the bottom one) is how I want it to be but the top one is the result that I get after rotating it (which is obvious since I rotate it by it's origin which is the center of the sensor and not the center of the tower's body).

I found the following thread about this:

So far I found 3 theoretical solutions:

1. Sliding the geom's LocalVertices around until the part that you want to rotate is over the body position. (doesn't this approach scramble the collision detection?)

2. Attach a new body in the point you want to rotate it with a fixed angle joint. Then rotate this body. (didn't work for me, it just did't want to rotate)

3. Reposition the sensor with a mathematical formula. (still looking for one as this is probably the best solution)

4. There is an overload in the GeomFactory that has a float rotationOffset parameter. ( I have no idea how to get this working)


Sorry for starting two threads so soon. Couldn't find/google a solution and I smashed my head figuring out a solution for it.

Apr 16, 2010 at 9:13 AM

You have or probably will read (the one useful time for having both present and past tenses conjugate to the same spelling from what I have noticed)

my other reply in your other thread my matrix advice, and yes, it applies here too.

Matrix-mathematics can be your friend, if you know how to use it.


If you really don't want to mess with it, then the best solution outside of it is to have two geoms attached to one body, where both geoms meet in the

center, as if you were putting two nun-chuks together. Only one of the geoms is your sensor, and the other one is practically disabled.



Apr 23, 2010 at 10:35 AM

I found the solution on Translating it from VB --> C# shouldn't be that hard.

Apr 24, 2010 at 7:14 PM

You should be able to simply move the local vertices to change there local origin and then rotate around that new origin.


Apr 30, 2010 at 1:59 PM

I tried moving the vertices:

body = BodyFactory.Instance.CreateRectangleBody(MyFarseer.PhysicsSimulator, width, height, 1); geom = GeomFactory.Instance.CreateRectangleGeom(MyFarseer.PhysicsSimulator, body, width, height); List<Vector2> vertices = new List<Vector2>(); foreach (Vector2 temp in geom.LocalVertices) vertices.Add(new Vector2(temp.X, temp.Y + (height / 2))); geom.SetVertices(new Vertices(vertices)); body.Position = position; geom.IsSensor = true; body.Rotation = rotation;

It does move the geom down but the body still rotates around it's old origin. How do I alter the vertices so that only the rotational-center is altered and nothing else?