List of usage examples for com.badlogic.gdx.math Vector2 isZero
@Override public boolean isZero()
From source file:com.mygdx.entities.DynamicEntities.SteerableEntity.java
private void applySteering() { boolean anyAccelerations = false; if (!steeringOutput.linear.isZero()) { Vector2 force = steeringOutput.linear.scl(MainGame.STEP); body.applyForceToCenter(force, true); anyAccelerations = true;/*from w w w.j a va 2s. co m*/ } if (steeringOutput.angular != 0) { body.applyTorque(steeringOutput.angular * MainGame.STEP, true); anyAccelerations = true; } else { Vector2 lv = getLinearVelocity(); if (!lv.isZero()) { float o = vectorToAngle(lv); body.setAngularVelocity((o - getAngularVelocity()) * MainGame.STEP); body.setTransform(body.getPosition(), o); } } if (anyAccelerations) { //linear capping Vector2 velocity = body.getLinearVelocity(); float currentSpeedSq = velocity.len2(); if (currentSpeedSq > maxLinearSpeed * maxLinearSpeed) { body.setLinearVelocity(velocity.scl(maxLinearSpeed / (float) Math.sqrt(currentSpeedSq))); } //angular capping if (body.getAngularVelocity() > maxAngularSpeed) { body.setAngularVelocity(maxAngularSpeed); } } }