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

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

Introduction

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

Prototype

public void applyForce(Vector2 force, Vector2 point, boolean wrap) 

Source Link

Document

Apply a force at a world point.

Usage

From source file:com.agateau.pixelwheels.utils.Box2DUtils.java

License:Open Source License

public static void applyDrag(Body body, float factor) {
    Vector2 dragForce = body.getLinearVelocity().scl(-factor);
    body.applyForce(dragForce, body.getWorldCenter(), true);
}

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

/**
 * Apply Froce to an entity/*from   w w w.j a  v  a 2 s.  c o  m*/
 *
 * @param world artemis world
 * @param entity entity that you want to apply
 * @param force force amount
 */
public static void applyForce(com.artemis.World world, Entity entity, Vector2 force) {
    Body body = getBody(world, entity);
    body.applyForce(force, body.getWorldCenter(), true);
}

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

public static void applyForce(Entity entity, Vector2 force) {
    Body body = getBody(entity);
    body.applyForce(force, body.getWorldCenter(), true);
}

From source file:com.gmail.emersonmx.asteroids.system.PhysicSystem.java

License:Open Source License

private void processInputEntity(Entity entity, float deltaTime) {
    MovementComponent motion = motionMapper.get(entity);
    PhysicBodyComponent bodyComponent = physicBodyMapper.get(entity);

    Body body = bodyComponent.body;
    body.applyForce(motion.velocity, body.getWorldCenter(), true);
    motion.velocity.setZero();/*from   w  w w  .  j  a  va2  s. c om*/

    body.setTransform(body.getPosition(), motion.direction.angleRad());
}

From source file:com.stercore.code.net.dermetfan.utils.libgdx.box2d.Autopilot.java

License:Apache License

/** applies the force from {@link #calculateForce(Vector2, Vector2)}
 *  @see #calculateForce(Vector2, Vector2)
 *  @see #move(Body, Vector2, Vector2, Interpolation, float, boolean) */
public void move(Body body, Vector2 destination, Vector2 force, boolean wake) {
    Vector2 position = positionAccessor.apply(body);
    Vector2 apply = calculateForce(moveRelative ? destination : vec2_0.set(destination).sub(position),
            adaptForceToMass ? vec2_1.set(force).scl(body.getMass()) : force);
    body.applyForce(apply, position, wake);
}

From source file:com.stercore.code.net.dermetfan.utils.libgdx.box2d.Autopilot.java

License:Apache License

/** applies the force of {@link #calculateForce(Vector2, Vector2, float, Interpolation)}
 *  @param body the body to move// ww w.j av a  2s . com
 *  @param destination the destination of the body
 *  @param force the force used to move the body
 *  @param interpolation the interpolation  used to interpolate the given {@code force} based on the {@code distanceScalar}
 *  @param distanceScalar the distance at which the force should be fully applied
 *  @param wake if the body should be woken up in case it is sleeping
 *  @see #move(Body, Vector2, Vector2, boolean)
 *  @see #calculateForce(Vector2, Vector2, float, Interpolation) */
public void move(Body body, Vector2 destination, Vector2 force, Interpolation interpolation,
        float distanceScalar, boolean wake) {
    Vector2 position = positionAccessor.apply(body);
    body.applyForce(calculateForce(moveRelative ? destination : vec2_0.set(destination).sub(position),
            adaptForceToMass ? vec2_1.set(force).scl(body.getMass()) : force, distanceScalar, interpolation),
            position, wake);
}

From source file:net.dermetfan.utils.libgdx.box2d.Autopilot.java

License:Apache License

/** applies the force from {@link #calculateForce(Vector2, Vector2, float)}
 *  @see #calculateForce(Vector2, Vector2, float, float, Interpolation)
 *  @see #move(Body, Vector2, Vector2, float, float, Interpolation, boolean) */
public void move(Body body, Vector2 destination, Vector2 force, boolean wake) {
    Vector2 position = positionAccessor.access(body);
    body.applyForce(calculateForce(moveRelative ? destination : vec2_0.set(destination).sub(position),
            adaptForceToMass ? vec2_1.set(force).scl(body.getMass()) : force), position, wake);
}

From source file:net.dermetfan.utils.libgdx.box2d.Autopilot.java

License:Apache License

/** applies the force of {@link #calculateForce(Vector2, Vector2, float, float, Interpolation)}
 *  @param body the body to move// w  w  w . ja v  a2s  .  c  o m
 *  @param destination the destination of the body
 *  @param force the force used to move the body
 *  @param interpolation the interpolation  used to interpolate the given {@code force} based on the {@code distanceScalar}
 *  @param distanceScalar the distance at which the force should be fully applied
 *  @param wake if the body should be woken up in case it is sleeping
 *  @see #move(Body, Vector2, Vector2, float, boolean)
 *  @see #calculateForce(Vector2, Vector2, float, Interpolation) */
public void move(Body body, Vector2 destination, Vector2 force, Interpolation interpolation,
        float distanceScalar, boolean wake) {
    Vector2 position = positionAccessor.access(body);
    body.applyForce(calculateForce(moveRelative ? destination : vec2_0.set(destination).sub(position),
            adaptForceToMass ? vec2_1.set(force).scl(body.getMass()) : force, distanceScalar, interpolation),
            position, wake);
}