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.
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));
}
float speedError = targetSpeed - argCurrLinearVel.length();
Vec2 direction = new Vec2(argCurrLinearVel);
direction.normalize();
return argDirection.mul( MathHelper.constrain(speedError, -argMaxForce, argMaxForce));
}