Problem with circles and character moves

ok, ok.

yes, mf should be argMaxForce, i didn't change that accidentally

MathHelper.constrain is meant to constrain the first value to the second two. This means that it makes sure that "speedError" doesnt go above mf or below -mf. You can write your own of that.

Here is a revised one for you. it returns the force to apply to achieve the target speed. argMaxForce is the maximum force to apply to the object.
Code:
public static Vec2 steerForTargetSpeed(Vec2 argCurrLinearVel, float argMaxForce, final float targetSpeed){
      float speedError = targetSpeed - argCurrLinearVel.length();
      Vec2 direction = new Vec2(argCurrLinearVel);
      direction.normalize();
      return argDirection.mul( MathHelper.constrain(speedError, -argMaxForce, argMaxForce));
   }
argDirection doesn't exists ...

I tried to correct the code, without maxForce (i don't want maxForce, i just have a target speed), but my character doesn't move.

Code:
   public static Vec2 steerForTargetSpeed(Vec2 argCurrLinearVel, final float targetSpeed) {
      float speedError = targetSpeed - argCurrLinearVel.length();
      Vec2 direction = argCurrLinearVel.clone();
      direction.normalize();
      return direction.mul(speedError);
   }
ok, you don't want your force to be over 3000 or something, cause the engine will go nuts. Did you do something like yourBody.applyForce( theResult, yourBody.getWorldCenter())? I think that's the syntax
I do this :

Code:
this.body.applyForce(steerForTargetSpeed(this.body.m_linearVelocity, value), new Vec2(0, 0));


Where value is positive or negative, depending on the direction.
you need to do some research into vector math
What is the problem ?
up
please research vector math and it's use with position/velocity/force. I could try to explain it but I think you'll find a much better explanation/tutorial somewhere else online.
I use it:
Code:
public void setSpeed(Vec2 targetV) {
      //mz'' = m*c => z' = ct + z'0 => Dz' =  cDt
      float dt = level.Dt; //dt of your world.step(dt);
      float m = body.getMass(); //mass of your body
      Vec2 currentV = body.getLinearVelocity();
      Vec2 deltaV = new Vec2(targetV.x-currentV.x,targetV.y-currentV.y);
      Vec2 deltaF = new Vec2(m*deltaV.x/dt,m*deltaV.y/dt);
      body.applyForce(deltaF, body.getWorldCenter());
      
   }



see the first comment:(I've changed it)
Quote:
//mz''(t) = c => z'(t) = ct/m + z'_0 => Dz' = z'(Dt)-z'_0 = cDt/m => c=Dz'*m/Dt

that's the diff.eq of a constant force
the tips is ( I think ) the force you set with body.applyForce is constant on all the dt of your world.step(dt)
Thank you.

Your function works perfectly for moving with applyForce 😀

But my problem is always here :s

My character can "enter" on other shapes, I don't understand why.

Original thread: https://box2d.org/forum/viewtopic.php?t=5385