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: http://farseerphysics.codeplex.com/Thread/View.aspx?ThreadId=72919
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.