Search in sources :

Example 1 with PhysicsSweepTestResult

use of com.jme3.bullet.collision.PhysicsSweepTestResult in project jmonkeyengine by jMonkeyEngine.

the class TestSweepTest method simpleUpdate.

@Override
public void simpleUpdate(float tpf) {
    float move = tpf * 1;
    boolean colliding = false;
    List<PhysicsSweepTestResult> sweepTest = bulletAppState.getPhysicsSpace().sweepTest(capsuleCollisionShape, new Transform(capsule.getWorldTranslation()), new Transform(capsule.getWorldTranslation().add(dist, 0, 0)));
    for (PhysicsSweepTestResult result : sweepTest) {
        if (result.getCollisionObject().getCollisionShape() != capsuleCollisionShape) {
            PhysicsCollisionObject collisionObject = result.getCollisionObject();
            fpsText.setText("Almost colliding with " + collisionObject.getUserObject().toString());
            colliding = true;
        }
    }
    if (!colliding) {
        // if the sweep is clear then move the spatial
        capsule.move(move, 0, 0);
    }
}
Also used : Transform(com.jme3.math.Transform) PhysicsSweepTestResult(com.jme3.bullet.collision.PhysicsSweepTestResult) PhysicsCollisionObject(com.jme3.bullet.collision.PhysicsCollisionObject)

Aggregations

PhysicsCollisionObject (com.jme3.bullet.collision.PhysicsCollisionObject)1 PhysicsSweepTestResult (com.jme3.bullet.collision.PhysicsSweepTestResult)1 Transform (com.jme3.math.Transform)1