C# Monogame Farseer Physics: Collisions

Topics: Developer Forum, Project Management Forum, User Forum
Nov 28, 2014 at 3:33 AM
Edited Nov 28, 2014 at 4:02 AM
I am a begginer. I am using Monogame and Farseer Physics Library in C#. (latest versions)

In my game, whenever my ball (circle) hits the corner of a rectangle, (or even another circle), it is supposed to only change direction on the Y-Axis.

However, it does not only change direction on the Y-Axis, (as intended), but it also moves a small amount to the right as well (or the left accordingly), depending on how you hit the corner (or another circle). It is as if some force is being put on the ball, making it move on X-Axis as well.


This movement is cool and all, and it makes a lot of sense, but in my game, it does not, therefore i want to get rid of it.

How is this possible ? I am guessing i have to change some default values.

This what my coding looks like:
BallBody.BodyType = BodyType.Dynamic;
BlockBody.BodyType = BodyType.Static;
Ball.LinearVelocity = new Vector(0,-1); // ball going up
BallBody.OnCollision += Ball_OnCollision;

public bool Ball_OnCollision(Fixture f1, Fixture f2, Contact contact)
    // if the Ball (f1), collides with the Block (f2)
    if (f2.Body == BlockBody)
    // change the direction of the Ball on Y-Axis
    Ball.LinearVelocity = new Vector(0,-1);
    return true;
Also with high speeds, this occurs:


Even though the ball is never able to pass through the Block (tunneling), I want to know how could i possible fix that so that the ball never enters the Block area ?
Dec 13, 2014 at 1:08 AM

1) What dimension are the blocks?

Try a lower 'LinearSlop' value in the settings.


Set Body.IsBullet to the ball. Also make ContinuousPhysics true in the settings.
You can also try lower step if your target platform can handle it.
If you are calling world.Step(t), try to call world.Step(t/2f) twice.
Dec 15, 2014 at 5:01 AM
Thank you, i managed to work around this "problem" i had by saving the velocity of the previous state and the velocity :) i will try your suggestions as well though