How to use only collision detection and disable the rotation response on collision? [SOLVED]

Topics: Developer Forum, User Forum
Aug 22, 2011 at 8:38 AM

Hey!

I am using Farseer physics because of its very good collision detection. I am not using physics in my game, i just need the collision detection system in order to detect.

I am going to explain simply my situation so i will avoid giving too much details of my project.

Lets say I am moving a sprite with "Position" and when it collides with a static object (a polygonal hitbox for example), I want my sprite to slide along the polygonal hitbox. I made tests and it works great.

BUT as you know, the physics are also rotating my sprite. What i want is like if both my sprite and the polygon were static. So my sprite can detect the polygon, move along the side and continues on his way, but without rotating the sprite nor the polygon ( a hitbox here).

I know its better to apply forces and impulsed instead of changing directly the position, but like i said i am not using physics stuff in my game, I just want to use de collision detection, and it works great except for the rotation response.

 

So I have several questions:

1) Is there a way to remove ONLY the rotation response from the collision? Because the impulse response (making my sprite slide along the hitbox) works perfectly.

I have tried already to give an angle (rotation) of 0 each frame but its glitchy.

2) Should I disable the collision response (to false) and handle the collision myself in the "onCollision" event?

I tried but then i really dont know how to handle the collision, it gets stuck. I tried other things but i dont manage to make my sprite slide along the hitbox. I definitely need the genious handling of farseer here :(  but without my sprite rotating.

3) Do you know some collision detection library other than farseer's that could help?

Because it seems that the collision detection of farseer is really much connected to the physics (of course because its a physics engine...) so it seems hard for me who want to move my objects "traditionaly" with no particular physics, to use farseer. In addition to this, I have already developping this game for 6 months already and i dont want to change everything.

 

Really big thanks for whoever could give me some hints,

I appreciate a lot :)

 

Groaker

Aug 22, 2011 at 3:15 PM

simple do body.FixedRotation = true; you don't need another library for this :)

Sep 1, 2011 at 10:02 AM

Hi HellGate!

Thank you so much for your reply, it completly solved my problem, thank you :)

Actually, I didnt find the body.FixedRotation because this is a feature in the version 3 of farseer.

I checked and I found that in farseer version 2, you need to do this:

body.MomentOfInertia = float.PositiveInfinity;

It does the exact same thing

 

Thanks again!