How to get rid of peak velocity (accelerate forever?)

Topics: User Forum
Nov 13, 2010 at 1:36 AM

Hello everyone,

I'm attempting to do something seemingly pretty simple - have two circles that fall without a peak velocity.  However, I can't seem to get rid of it.

Below is my code, with what seems like an obscenely high gravity, yet when I am printing the linear velocity of my circles each frame, it steadies at about 120 in Y.  The numbers actually occur anywhere between about 100 and 140, but most are pretty close to 120.  Older posts led me to believe I needed to change a linear drag coefficient, but all I seem to be able to find is linear damping -- did it change names?  No matter what I seem to set for density, friction, and linear damping, I can't get past this value of 120 in the Y.

What incredibly silly thing am I doing wrong?  Thanks for your help.

 

class Gameplay : AEngineState
{
    FPSMonitor m_fpsMonitor = new FPSMonitor();
    
    World m_world = new World(new Vector2(0, 1000000));

    List<Fixture> m_fixtures = new List<Fixture>();

    public Gameplay()
        : base()
    {
        // 1
        
        Fixture circleFixture = FixtureFactory.CreateCircle(m_world, 40, 0.001f, new Vector2(100, 100));

        circleFixture.Body.BodyType = BodyType.Dynamic;
        circleFixture.Body.LinearDamping = 0.0f;

        circleFixture.Restitution = 0.3f;
        circleFixture.Friction = 0.0f;

        m_fixtures.Add(circleFixture);

        // 2

        circleFixture = FixtureFactory.CreateCircle(m_world, 40, 0.001f, new Vector2(300, 100));

        circleFixture.Body.BodyType = BodyType.Dynamic;
        circleFixture.Body.LinearDamping = 0.0f;

        circleFixture.Restitution = 0.6f;
        circleFixture.Friction = 0.0f;

        m_fixtures.Add(circleFixture);
    }

    #region IEngineState Members

    public override void Update(GameTime gameTime)
    {
        m_fpsMonitor.Update(gameTime);

        m_world.Step((float)gameTime.ElapsedGameTime.TotalMilliseconds * 0.001f);
    }

    public override void Draw(GameTime gameTime)
    {
        m_fpsMonitor.Draw(gameTime);

        foreach (Fixture f in m_fixtures)
        {
            System.Console.WriteLine(f.Body.LinearVelocity);

            Primitives.Instance.drawCircle(
                Engine.Instance.SpriteBatch,
                f.Body.Position,
                40,
                Color.Black,
                1);
        }
    }

    #endregion
}

Coordinator
Nov 13, 2010 at 2:02 AM

Linear damping and linear drag is basically the same. But even if you remove all damping, you will still be limited by the engine. There is a Settings.MaxTranslation variable that limits the maximum translation (movement) a body can make. You will have to change that in order for the bodies to go faster.

That being said, I don't recommend changing the variable. Weird things happen when you reach high velocities in the engine.

Nov 13, 2010 at 9:26 AM

Thanks Genbox, that solved my problem.

Now I'm scaling down all my coordinates when I add objects to the World, and scaling them back up when I render them.  Seems to work well.