Example usage for com.badlogic.gdx.physics.box2d Body applyLinearImpulse

List of usage examples for com.badlogic.gdx.physics.box2d Body applyLinearImpulse

Introduction

In this page you can find the example usage for com.badlogic.gdx.physics.box2d Body applyLinearImpulse.

Prototype

public void applyLinearImpulse(Vector2 impulse, Vector2 point, boolean wake) 

Source Link

Document

Apply an impulse at a point.

Usage

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

License:Open Source License

private void applySimplifiedRacerCollision(Racer other) {
    Body body1 = getVehicle().getBody();
    Body body2 = other.getVehicle().getBody();

    mTmp.set(body2.getLinearVelocity()).sub(body1.getLinearVelocity());
    float deltaV = mTmp.len();

    final float k = GamePlay.instance.simplifiedCollisionKFactor
            * MathUtils.clamp(deltaV / GamePlay.instance.simplifiedCollisionMaxDeltaV, 0, 1);
    mTmp.set(body2.getWorldCenter()).sub(body1.getWorldCenter()).nor().scl(k);

    body2.applyLinearImpulse(mTmp, body2.getWorldCenter(), true);
    mTmp.scl(-1);/*  w  w w .  jav  a 2s .c o  m*/
    body1.applyLinearImpulse(mTmp, body1.getWorldCenter(), true);
}

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

License:Open Source License

@Override
public void act(float delta) {
    if (!mActive) {
        return;//from   w  w w . j  a v a  2 s. c om
    }
    Body body = mVehicle.getBody();

    // Slow down
    body.applyLinearImpulse(body.getLinearVelocity().nor().scl(-body.getMass()), body.getWorldCenter(), true);

    // Spin
    float nextAngle = body.getAngle() + body.getAngularVelocity() * GameWorld.BOX2D_TIME_STEP;
    if (nextAngle > mTargetBodyAngle) {
        stopSpinning();
        return;
    }

    float totalRotation = mTargetBodyAngle - nextAngle;
    float desiredAngularVelocity = totalRotation / GameWorld.BOX2D_TIME_STEP;
    if (desiredAngularVelocity < 0) {
        desiredAngularVelocity = MathUtils.clamp(desiredAngularVelocity, -MAX_ANGULAR_VELOCITY,
                -MIN_ANGULAR_VELOCITY);
    } else {
        desiredAngularVelocity = MathUtils.clamp(desiredAngularVelocity, MIN_ANGULAR_VELOCITY,
                MAX_ANGULAR_VELOCITY);
    }
    float impulse = body.getInertia() * (desiredAngularVelocity - body.getAngularVelocity());
    body.applyAngularImpulse(impulse, true);
}

From source file:com.dongbat.game.util.PhysicsUtil.java

/**
 * Apply Linear Impulse to an entity//from   w ww.  j a v  a  2s .  co  m
 *
 * @param world artemis world
 * @param entity entity that you want to apply
 * @param impulse impulse amount
 */
public static void applyImpulse(com.artemis.World world, Entity entity, Vector2 impulse) {
    Body body = getBody(world, entity);
    body.applyLinearImpulse(impulse, body.getWorldCenter(), true);
}

From source file:com.dongbat.invasion.util.PhysicsUtil.java

public static void applyImpulse(Entity entity, Vector2 impulse) {
    Body body = getBody(entity);
    body.applyLinearImpulse(impulse, body.getWorldCenter(), true);
}

From source file:com.hatstick.fireman.physics.Box2DPhysicsWorld.java

License:Apache License

public void jumpBody(Body body, float height) {
    body.applyLinearImpulse(new Vector2(0, height), body.getWorldCenter(), true);
}