Search in sources :

Example 1 with CharacterMovementComponent

use of org.terasology.logic.characters.CharacterMovementComponent in project Terasology by MovingBlocks.

the class BulletPhysics method createCharacterCollider.

/**
 * Creates a Collider for the given entity based on the LocationComponent
 * and CharacterMovementComponent.
 * All collision flags are set right for a character movement component.
 *
 * @param owner the entity to create the collider for.
 * @return
 */
private CharacterCollider createCharacterCollider(EntityRef owner) {
    LocationComponent locComp = owner.getComponent(LocationComponent.class);
    CharacterMovementComponent movementComp = owner.getComponent(CharacterMovementComponent.class);
    if (locComp == null || movementComp == null) {
        throw new IllegalArgumentException("Expected an entity with a Location component and CharacterMovementComponent.");
    }
    Vector3f pos = VecMath.to(locComp.getWorldPosition());
    final float worldScale = locComp.getWorldScale();
    final float height = (movementComp.height - 2 * movementComp.radius) * worldScale;
    final float width = movementComp.radius * worldScale;
    ConvexShape shape = new CapsuleShape(width, height);
    shape.setMargin(0.1f);
    return createCustomCollider(pos, shape, movementComp.collisionGroup.getFlag(), combineGroups(movementComp.collidesWith), CollisionFlags.CHARACTER_OBJECT, owner);
}
Also used : Vector3f(javax.vecmath.Vector3f) ConvexShape(com.bulletphysics.collision.shapes.ConvexShape) CharacterMovementComponent(org.terasology.logic.characters.CharacterMovementComponent) LocationComponent(org.terasology.logic.location.LocationComponent) CapsuleShape(com.bulletphysics.collision.shapes.CapsuleShape)

Example 2 with CharacterMovementComponent

use of org.terasology.logic.characters.CharacterMovementComponent in project Terasology by MovingBlocks.

the class MovementDebugCommands method stepHeight.

@Command(shortDescription = "Sets the height the player can step up", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String stepHeight(@Sender EntityRef client, @CommandParam("height") float amount) {
    ClientComponent clientComp = client.getComponent(ClientComponent.class);
    CharacterMovementComponent move = clientComp.character.getComponent(CharacterMovementComponent.class);
    if (move != null) {
        float prevStepHeight = move.stepHeight;
        move.stepHeight = amount;
        clientComp.character.saveComponent(move);
        return "Ground friction set to " + amount + " (was " + prevStepHeight + ")";
    }
    return "";
}
Also used : CharacterMovementComponent(org.terasology.logic.characters.CharacterMovementComponent) ClientComponent(org.terasology.network.ClientComponent) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 3 with CharacterMovementComponent

use of org.terasology.logic.characters.CharacterMovementComponent in project Terasology by MovingBlocks.

the class MovementDebugCommands method playerHeight.

@Command(shortDescription = "Sets the height of the player", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String playerHeight(@Sender EntityRef client, @CommandParam("height") float amount) {
    try {
        ClientComponent clientComp = client.getComponent(ClientComponent.class);
        CharacterMovementComponent move = clientComp.character.getComponent(CharacterMovementComponent.class);
        if (move != null) {
            float prevHeight = move.height;
            move.height = amount;
            clientComp.character.saveComponent(move);
            LocationComponent loc = client.getComponent(LocationComponent.class);
            Vector3f currentPosition = loc.getWorldPosition();
            clientComp.character.send(new CharacterTeleportEvent(new Vector3f(currentPosition.getX(), currentPosition.getY() + (amount - prevHeight) / 2, currentPosition.getZ())));
            physics.removeCharacterCollider(clientComp.character);
            physics.getCharacterCollider(clientComp.character);
            return "Height of player set to " + amount + " (was " + prevHeight + ")";
        }
        return "";
    } catch (NullPointerException e) {
        e.printStackTrace();
        return "";
    }
}
Also used : CharacterTeleportEvent(org.terasology.logic.characters.CharacterTeleportEvent) Vector3f(org.terasology.math.geom.Vector3f) CharacterMovementComponent(org.terasology.logic.characters.CharacterMovementComponent) ClientComponent(org.terasology.network.ClientComponent) LocationComponent(org.terasology.logic.location.LocationComponent) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 4 with CharacterMovementComponent

use of org.terasology.logic.characters.CharacterMovementComponent in project Terasology by MovingBlocks.

the class MovementDebugCommands method setJumpSpeed.

@Command(shortDescription = "Set jump speed", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String setJumpSpeed(@Sender EntityRef client, @CommandParam("amount") float amount) {
    ClientComponent clientComp = client.getComponent(ClientComponent.class);
    CharacterMovementComponent move = clientComp.character.getComponent(CharacterMovementComponent.class);
    if (move != null) {
        float oldSpeed = move.jumpSpeed;
        move.jumpSpeed = amount;
        clientComp.character.saveComponent(move);
        return "Jump speed set to " + amount + " (was " + oldSpeed + ")";
    }
    return "";
}
Also used : CharacterMovementComponent(org.terasology.logic.characters.CharacterMovementComponent) ClientComponent(org.terasology.network.ClientComponent) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 5 with CharacterMovementComponent

use of org.terasology.logic.characters.CharacterMovementComponent in project Terasology by MovingBlocks.

the class MovementDebugCommands method showMovement.

@Command(shortDescription = "Show your Movement stats", requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String showMovement(@Sender EntityRef client) {
    ClientComponent clientComp = client.getComponent(ClientComponent.class);
    CharacterMovementComponent move = clientComp.character.getComponent(CharacterMovementComponent.class);
    if (move != null) {
        return "Your SpeedMultiplier:" + move.speedMultiplier + " JumpSpeed:" + move.jumpSpeed + " SlopeFactor:" + move.slopeFactor + " RunFactor:" + move.runFactor;
    }
    return "You're dead I guess.";
}
Also used : CharacterMovementComponent(org.terasology.logic.characters.CharacterMovementComponent) ClientComponent(org.terasology.network.ClientComponent) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Aggregations

CharacterMovementComponent (org.terasology.logic.characters.CharacterMovementComponent)18 Command (org.terasology.logic.console.commandSystem.annotations.Command)11 ClientComponent (org.terasology.network.ClientComponent)11 LocationComponent (org.terasology.logic.location.LocationComponent)3 Vector3f (org.terasology.math.geom.Vector3f)3 CapsuleShape (com.bulletphysics.collision.shapes.CapsuleShape)2 Vector3f (javax.vecmath.Vector3f)2 EntityRef (org.terasology.entitySystem.entity.EntityRef)2 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)2 Prefab (org.terasology.entitySystem.prefab.Prefab)2 CharacterTeleportEvent (org.terasology.logic.characters.CharacterTeleportEvent)2 BoxShape (com.bulletphysics.collision.shapes.BoxShape)1 ConvexHullShape (com.bulletphysics.collision.shapes.ConvexHullShape)1 ConvexShape (com.bulletphysics.collision.shapes.ConvexShape)1 CylinderShape (com.bulletphysics.collision.shapes.CylinderShape)1 SphereShape (com.bulletphysics.collision.shapes.SphereShape)1 ObjectArrayList (com.bulletphysics.util.ObjectArrayList)1 TFloatIterator (gnu.trove.iterator.TFloatIterator)1 ArrayList (java.util.ArrayList)1 ResourceUrn (org.terasology.assets.ResourceUrn)1