Search in sources :

Example 1 with LinearVelocityLimitComponent

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);
    }
}
Also used : PhysicsComponent(com.gemserk.commons.artemis.components.PhysicsComponent) Vector2(com.badlogic.gdx.math.Vector2) Body(com.badlogic.gdx.physics.box2d.Body) LinearVelocityLimitComponent(com.gemserk.commons.artemis.components.LinearVelocityLimitComponent)

Aggregations

Vector2 (com.badlogic.gdx.math.Vector2)1 Body (com.badlogic.gdx.physics.box2d.Body)1 LinearVelocityLimitComponent (com.gemserk.commons.artemis.components.LinearVelocityLimitComponent)1 PhysicsComponent (com.gemserk.commons.artemis.components.PhysicsComponent)1