Sign in to follow this  
Kaan Aksoy

Farseer Physics Movement XNA

Recommended Posts

Kaan Aksoy    109
Hey. I am working on a 2D Terraria-Like game, and I needed some help with the movement. To handle both collisions and physics, I am using the Farseer Physics Engine. I have two questions, which are probably quite simple.

1. How can I make my character stop moving once the movement keys are released. With the code below, the character still continues to roll:

[source lang="java"]if(k.IsKeyDown(Keys.Left))
{

circleBody.ApplyTorque(-1000);
}
else if (k.IsKeyDown(Keys.Right))
{
circleBody.ApplyTorque(1000);
}[/source]
2. Can I make the character not bounce at all after colliding with a platform? I have set the RestitutionCoefficient to 0, but it still bounces a very small amount.

3. Is there a way to prevent the character from rotating its texture?

Thanks for the help

Share this post


Link to post
Share on other sites
Bayinx    153
[quote name='Kaandimandimanbopbobop' timestamp='1339533366' post='4948622']
Hey. I am working on a 2D Terraria-Like game, and I needed some help with the movement. To handle both collisions and physics, I am using the Farseer Physics Engine. I have two questions, which are probably quite simple.

1. How can I make my character stop moving once the movement keys are released. With the code below, the character still continues to roll:
[/quote]

As can see in the source code of the Body class there is a method called ResetDynamics(). I believe that this method is the one you are looking for.

[quote name='Kaandimandimanbopbobop' timestamp='1339533366' post='4948622']
[left][background=rgb(250, 251, 252)]2. Can I make the character not bounce at all after colliding with a platform? I have set the RestitutionCoefficient to 0, but it still bounces a very small amount.[/background][/left]

[/quote]

I am not sure about this one, but try also setting the ground restitution to 0.


[quote name='Kaandimandimanbopbobop' timestamp='1339533366' post='4948622']
3. Is there a way to prevent the character from rotating its texture?
[/quote]
There is a propriety in the class Body name FixedRotation. Set it to true to have the character keep its rotation to 0.

Hope this is helpful ;). Edited by Bayinx

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this