Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm working on my top-down game. y characters use pathfinding + steering behaviors(Arrive and FollowPath) to move. I've implemented my character class from libgdx SteeringActor class (from tests). So the question, how can I limit the angular speed to make characters not turn around instantly.

private void applySteering(SteeringAcceleration<Vector2> steering,
        float time) {
    // Update position and linear velocity. Velocity is trimmed to maximum
    // speed
    position.mulAdd(linearVelocity, time);
    setX(position.x);
    setY(position.y);
    linearVelocity.mulAdd(steering.linear, time).limit(getMaxLinearSpeed());
    // Update orientation and angular velocity
    if (independentFacing) {
        setRotation(getRotation() + (angularVelocity * time)
                * MathUtils.radiansToDegrees);
        angularVelocity += steering.angular * time;
        body.move(position, getRotation());
    } else {
        // If we haven't got any velocity, then we can do nothing.
        if (!linearVelocity.isZero(0.001f)) {
            float newOrientation = vectorToAngle(linearVelocity);
            angularVelocity = (newOrientation - getRotation()
                    * MathUtils.degreesToRadians)
                    * time; // this is superfluous if independentFacing is
                            // always true
            body.move(position, newOrientation);
            setRotation(newOrientation * MathUtils.radiansToDegrees);
        }
    }
}  

So there is limiter for linear speed,but no limiter for angular. (IndependentFacing = false;)
body.move()-is function to rotate and move collision representation of character. body is object of my class, I'm not using Box2d.

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.