use of com.gemserk.commons.artemis.components.LinearVelocityLimitComponent in project commons-gdx by gemserk.
the class LimitLinearVelocitySystem method process.
@Override
protected void process(Entity e) {
PhysicsComponent physicsComponent = Components.getPhysicsComponent(e);
Body body = physicsComponent.getPhysics().getBody();
LinearVelocityLimitComponent limitComponent = e.getComponent(LinearVelocityLimitComponent.class);
Vector2 linearVelocity = body.getLinearVelocity();
float speed = linearVelocity.len();
float maxSpeed = limitComponent.getLimit();
if (speed > maxSpeed) {
float factor = maxSpeed / speed;
linearVelocity.mul(factor);
body.setLinearVelocity(linearVelocity);
}
}
Aggregations