Loading
Dev Blog: Project Moldering

Added friction to moldering, both for air and ground. The equation is:

Acceleration = Acceleration - (Acceleration*u);

where u is friction. This value is different depending on whether player is on ground or in air. For example, I set u to .35 when on the ground. This prevents the player from slipping around. However, I can make this value lower to simulate ice, or higher to simulate sand.

-James

Bookmark and Share

Solved: See this post.

So, now that I have drag, expressed as:

        k1=.09;
        k2=.01;
        drag=(k1*accAccumX)+
             (k2*(accAccumX*Math.abs(accAccumX)));
        accAccumX-=drag;
        grandVelX=accAccumX;

My objects will reach a maximum velocity and slow down accordingly. However, they don’t slow down appropriately when on the ground. What I need to devise is a friction when the player is on the ground. This way he doesn’t float along until drag is enough to stop him, but rather stops the player quickly when the controls are released. Like in real life, friction will stop you quickly instead of letting you drag on. Then I can change the value when the player is on ice, or sand, or just grass and have the appropriate effect.

I’ve been looking into it and I can’t find exactly what I am looking for.


Possible solutions:


1. increase the drag (or create a new one) when the player is on the ground, although this isn’t necessarily the best way.

2. Create a new variable ‘friction’ and do something like this:

      if (player is on ground)
          velocity = velocity * friction;

This doesn’t seem right either.

Any thoughts?

Bookmark and Share