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 "";
}
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 "";
}
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);
}
});
}
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);
}
}
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);
}
Aggregations