Example usage for com.badlogic.gdx.math Vector2 limit

List of usage examples for com.badlogic.gdx.math Vector2 limit

Introduction

In this page you can find the example usage for com.badlogic.gdx.math Vector2 limit.

Prototype

@Override
    public Vector2 limit(float limit) 

Source Link

Usage

From source file:com.agateau.pixelwheels.racer.Wheel.java

License:Open Source License

private void updateFriction() {
    // Kill lateral velocity
    Vector2 impulse = Box2DUtils.getLateralVelocity(mBody).scl(-mBody.getMass()).scl(mMaterial.getGrip());
    float maxImpulse = (float) GamePlay.instance.maxLateralImpulse / (mVehicle.isBraking() ? 0.2f : 1);
    if (mMaterial != Material.ICE && mCanDrift && impulse.len() > maxImpulse) {
        // Drift/*from  w ww.j  a  va  2s  .co m*/
        mDrifting = true;
        if (mSkidmarkCount == 0) {
            mSkidmarks.add().init(mBody.getWorldCenter());
        }
        mSkidmarkCount = (mSkidmarkCount + 1) % SKIDMARK_INTERVAL;
        maxImpulse = Math.max(maxImpulse, impulse.len() - DRIFT_IMPULSE_REDUCTION);
        impulse.limit(maxImpulse);
    } else if (mDrifting) {
        mSkidmarks.add().initAsEnd();
        mDrifting = false;
    }
    mBody.applyLinearImpulse(impulse, mBody.getWorldCenter(), true);

    // Kill angular velocity
    mBody.applyAngularImpulse(0.1f * mBody.getInertia() * -mBody.getAngularVelocity(), true);
}

From source file:de.cubicvoxel.openspacebox.ingame.object.Ship.java

License:Open Source License

private void moveTowards(Vector2 direction, float delta) {
    Vector2 movement = new Vector2(direction);
    movement.scl(shipType.getPhysics().getAcceleration() * delta);

    Vector2 totalVelocity = new Vector2(velocity).add(movement);
    totalVelocity.limit(getMaxSpeed());
    velocity = totalVelocity;/* w  w  w.  j a va2s .  c  o  m*/
}