I am creating a 2D platformer using farseer physics engine, I am having the hardest of times trying to figure out how to use OnCollision, even though I saw
, I am still trying to grasp the concept. This is what I am working
. I want to know when the player is hitting ground so I can have a bool that is called isJumping. When the player is jumping, isJumping is true so that the player does not keep jumping.
(I also want to have a ground bool that will say, "hay your on the ground".)
The problem with this code is that I will get a null reference. I am also only detecting the floor were I am also using red rectangles as well. How do I detect all the objects not just the floor physics object?
public bool OnCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
if (fixtureA.Body.GetType() == Person.GetType() & fixtureB.Body.GetType() == game1.floor.GetType())
ground = true;
isJumping = false;
I am also having an issue with the sliding of the player when I let go of the left or right arrow key. The player will just keep going, slowly decelerating. I have gotten it so that the player will slow down more dramatically but its acts like it hit a wall
I want a quick stop with about a .1 to .25 delay from the speed the player was going to stopped.
public void SlowDown()
KeyboardState keyboardState = Keyboard.GetState();
xForce = Person.Body.LinearVelocity.X;
if (Person.Body.LinearVelocity.X > 0 && !keyboardState.IsKeyDown(Keys.Right))
if (Person.Body.LinearVelocity.X > 1)
pushForce = xForce + 1;
pushForce = 0;
right = new Vector2(-pushForce, 0);
else if (Person.Body.LinearVelocity.X < 0 && !keyboardState.IsKeyDown(Keys.Left))
if (Person.Body.LinearVelocity.X < -1)
pushForce = xForce - 1;
pushForce = 0;
left = new Vector2(-pushForce, 0);