Search in sources :

Example 6 with CharacterMovementComponent

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

the class MovementDebugCommands method hspeed.

@Command(shortDescription = "Go really fast", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String hspeed(@Sender EntityRef client) {
    ClientComponent clientComp = client.getComponent(ClientComponent.class);
    CharacterMovementComponent move = clientComp.character.getComponent(CharacterMovementComponent.class);
    if (move != null) {
        move.speedMultiplier = 10f;
        move.jumpSpeed = 24f;
        clientComp.character.saveComponent(move);
        return "High-speed mode activated";
    }
    return "";
}
Also used : CharacterMovementComponent(org.terasology.logic.characters.CharacterMovementComponent) ClientComponent(org.terasology.network.ClientComponent) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 7 with CharacterMovementComponent

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

the class MovementDebugCommands method setSpeedMultiplier.

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

Example 8 with CharacterMovementComponent

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

the class AnimationScreen method initialise.

@Override
public void initialise() {
    spawnEntityIdButton = find("spawnEntityIdButton", UIButton.class);
    entityDropdown = find("entityDropdown", UIDropdownScrollable.class);
    logger.info("Number of available skeletal meshes: " + assetManager.getAvailableAssets(SkeletalMesh.class).size());
    ArrayList skeletalMesh = new ArrayList(assetManager.getAvailableAssets(SkeletalMesh.class));
    if (entityDropdown != null) {
        entityDropdown.setOptions(skeletalMesh);
    }
    animationSpeedSlider = find("entityAnimationSpeedSlider", UISlider.class);
    if (animationSpeedSlider != null) {
        animationSpeedSlider.setMinimum(-0.0f);
        animationSpeedSlider.setIncrement(0.1f);
        animationSpeedSlider.setRange(10.0f);
        animationSpeedSlider.setPrecision(1);
    }
    spawnEntityIdButton.subscribe(widget -> {
        Vector3f localPlayerPosition = localPlayer.getPosition();
        Quat4f localPlayerRotation = localPlayer.getRotation();
        Vector3f offset = localPlayer.getViewDirection();
        offset.scale(2.0f);
        offset.y = 0;
        localPlayerPosition.add(offset);
        Optional<Prefab> prefab = assetManager.getAsset(entityDropdown.getSelection(), Prefab.class);
        if (prefab.isPresent() && prefab.get().getComponent(LocationComponent.class) != null) {
            entityRef = entityManager.create(prefab.get(), localPlayerPosition, localPlayerRotation);
            SkeletalMeshComponent skeletalMeshComponent = entityRef.getComponent(SkeletalMeshComponent.class);
            skeletalMeshComponent.animationRate = animationSpeedSlider.getValue();
            entityRef.saveComponent(skeletalMeshComponent);
            CharacterMovementComponent movementComponent = entityRef.getComponent(CharacterMovementComponent.class);
            movementComponent.speedMultiplier = animationSpeedSlider.getValue();
            entityRef.saveComponent(movementComponent);
        }
    });
}
Also used : SkeletalMeshComponent(org.terasology.rendering.logic.SkeletalMeshComponent) UISlider(org.terasology.rendering.nui.widgets.UISlider) UIButton(org.terasology.rendering.nui.widgets.UIButton) UIDropdownScrollable(org.terasology.rendering.nui.widgets.UIDropdownScrollable) Vector3f(org.terasology.math.geom.Vector3f) ArrayList(java.util.ArrayList) CharacterMovementComponent(org.terasology.logic.characters.CharacterMovementComponent) SkeletalMesh(org.terasology.rendering.assets.skeletalmesh.SkeletalMesh) Prefab(org.terasology.entitySystem.prefab.Prefab) Quat4f(org.terasology.math.geom.Quat4f)

Example 9 with CharacterMovementComponent

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

the class SimpleAISystem method onBump.

@ReceiveEvent(components = { SimpleAIComponent.class })
public void onBump(HorizontalCollisionEvent event, EntityRef entity) {
    CharacterMovementComponent moveComp = entity.getComponent(CharacterMovementComponent.class);
    if (moveComp != null && moveComp.grounded) {
        moveComp.jump = true;
        entity.saveComponent(moveComp);
    }
}
Also used : CharacterMovementComponent(org.terasology.logic.characters.CharacterMovementComponent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 10 with CharacterMovementComponent

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

the class BulletPhysics method getShapeFor.

/**
 * Returns the shape belonging to the given entity. It currently knows 4
 * different shapes: Sphere, Capsule, Cylinder or arbitrary.
 * The shape is determined based on the shape component of the given entity.
 * If the entity has somehow got multiple shapes, only one is picked. The
 * order of priority is: Sphere, Capsule, Cylinder, arbitrary.
 * <br><br>
 * TODO: Flyweight this (take scale as parameter)
 *
 * @param entity the entity to get the shape of.
 * @return the shape of the entity, ready to be used by Bullet.
 */
private ConvexShape getShapeFor(EntityRef entity) {
    BoxShapeComponent box = entity.getComponent(BoxShapeComponent.class);
    if (box != null) {
        Vector3f halfExtents = new Vector3f(VecMath.to(box.extents));
        halfExtents.scale(0.5f);
        return new BoxShape(halfExtents);
    }
    SphereShapeComponent sphere = entity.getComponent(SphereShapeComponent.class);
    if (sphere != null) {
        return new SphereShape(sphere.radius);
    }
    CapsuleShapeComponent capsule = entity.getComponent(CapsuleShapeComponent.class);
    if (capsule != null) {
        return new CapsuleShape(capsule.radius, capsule.height);
    }
    CylinderShapeComponent cylinder = entity.getComponent(CylinderShapeComponent.class);
    if (cylinder != null) {
        return new CylinderShape(new Vector3f(cylinder.radius, 0.5f * cylinder.height, cylinder.radius));
    }
    HullShapeComponent hull = entity.getComponent(HullShapeComponent.class);
    if (hull != null) {
        ObjectArrayList<Vector3f> verts = new ObjectArrayList<>();
        TFloatIterator iterator = hull.sourceMesh.getVertices().iterator();
        while (iterator.hasNext()) {
            Vector3f newVert = new Vector3f();
            newVert.x = iterator.next();
            newVert.y = iterator.next();
            newVert.z = iterator.next();
            verts.add(newVert);
        }
        return new ConvexHullShape(verts);
    }
    CharacterMovementComponent characterMovementComponent = entity.getComponent(CharacterMovementComponent.class);
    if (characterMovementComponent != null) {
        return new CapsuleShape(characterMovementComponent.radius, characterMovementComponent.height);
    }
    logger.error("Creating physics object that requires a ShapeComponent or CharacterMovementComponent, but has neither. Entity: {}", entity);
    throw new IllegalArgumentException("Creating physics object that requires a ShapeComponent or CharacterMovementComponent, but has neither. Entity: " + entity);
}
Also used : SphereShapeComponent(org.terasology.physics.components.shapes.SphereShapeComponent) ConvexHullShape(com.bulletphysics.collision.shapes.ConvexHullShape) CylinderShapeComponent(org.terasology.physics.components.shapes.CylinderShapeComponent) HullShapeComponent(org.terasology.physics.components.shapes.HullShapeComponent) CharacterMovementComponent(org.terasology.logic.characters.CharacterMovementComponent) CapsuleShapeComponent(org.terasology.physics.components.shapes.CapsuleShapeComponent) CylinderShape(com.bulletphysics.collision.shapes.CylinderShape) ObjectArrayList(com.bulletphysics.util.ObjectArrayList) Vector3f(javax.vecmath.Vector3f) TFloatIterator(gnu.trove.iterator.TFloatIterator) BoxShapeComponent(org.terasology.physics.components.shapes.BoxShapeComponent) SphereShape(com.bulletphysics.collision.shapes.SphereShape) BoxShape(com.bulletphysics.collision.shapes.BoxShape) CapsuleShape(com.bulletphysics.collision.shapes.CapsuleShape)

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