use of org.terasology.engine.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class CharacterMovementSystemUtility method extrapolateLocationComponent.
private void extrapolateLocationComponent(EntityRef entity, CharacterStateEvent state, Vector3f newPos) {
LocationComponent location = entity.getComponent(LocationComponent.class);
location.setWorldPosition(newPos);
location.setWorldRotation(state.getRotation());
entity.saveComponent(location);
}
use of org.terasology.engine.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class CharacterMovementSystemUtility method setToState.
/**
* Sets the state of the given entity to the state represented by the
* CharacterStateEvent. The state of the entity is determined by its
* LocationComponent (location and orientation of physics body),
* CharacterMovementComponent (velocity and various movement state
* variables) and CharacterComponent for pitch and yaw (used for the camera).
*
* @param entity
* @param state
*/
public void setToState(EntityRef entity, CharacterStateEvent state) {
LocationComponent location = entity.getComponent(LocationComponent.class);
CharacterMovementComponent movementComp = entity.getComponent(CharacterMovementComponent.class);
if (location == null || !location.getWorldPosition(new Vector3f()).isFinite() || movementComp == null) {
return;
}
location.setWorldPosition(state.getPosition());
location.setWorldRotation(state.getRotation());
entity.saveComponent(location);
movementComp.mode = state.getMode();
movementComp.setVelocity(state.getVelocity());
movementComp.grounded = state.isGrounded();
movementComp.footstepDelta = state.getFootstepDelta();
entity.saveComponent(movementComp);
setPhysicsLocation(entity, state.getPosition());
// set the pitch to the character's gaze entity
Quaternionf rotation = new Quaternionf().rotationX(TeraMath.DEG_TO_RAD * state.getPitch());
EntityRef gazeEntity = GazeAuthoritySystem.getGazeEntityForCharacter(entity);
if (!gazeEntity.equals(entity)) {
// Only set the gaze entity rotation if it is not the same as the main entity.
// The character is assumed to only rotate side to side, introducing pitch makes things act strangely
LocationComponent gazeLocation = gazeEntity.getComponent(LocationComponent.class);
gazeLocation.setLocalRotation(rotation);
gazeEntity.saveComponent(gazeLocation);
}
}
use of org.terasology.engine.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class VisualCharacterSystem method createAndAttachVisualEntity.
private EntityRef createAndAttachVisualEntity(EntityBuilder entityBuilder, EntityRef characterEntity) {
entityBuilder.setPersistent(false);
entityBuilder.setOwner(characterEntity);
entityBuilder.addOrSaveComponent(new LocationComponent());
EntityRef visualCharacterEntity = entityBuilder.build();
Location.attachChild(characterEntity, visualCharacterEntity, new Vector3f(), new Quaternionf());
return visualCharacterEntity;
}
use of org.terasology.engine.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class ActivationPredicted method getInstigatorLocation.
public Vector3f getInstigatorLocation() {
LocationComponent loc = instigator.getComponent(LocationComponent.class);
if (loc != null) {
Vector3f result = loc.getWorldPosition(new Vector3f());
if (result.isFinite()) {
return result;
}
result.set(0, 0, 0);
return result;
}
return new Vector3f();
}
use of org.terasology.engine.logic.location.LocationComponent in project Terasology by MovingBlocks.
the class PlayerSystem method setSpawnLocationOnRespawnRequest.
@ReceiveEvent(priority = EventPriority.PRIORITY_CRITICAL, components = ClientComponent.class)
public void setSpawnLocationOnRespawnRequest(RespawnRequestEvent event, EntityRef entity) {
ClientComponent clientComponent = entity.getComponent(ClientComponent.class);
EntityRef character = clientComponent.character;
EntityRef clientInfo = clientComponent.clientInfo;
Vector3fc spawnPosition;
if (clientInfo.hasComponent(StaticSpawnLocationComponent.class)) {
spawnPosition = clientInfo.getComponent(StaticSpawnLocationComponent.class).position;
} else {
spawnPosition = worldGenerator.getSpawnPosition(entity);
}
LocationComponent loc = character.getComponent(LocationComponent.class);
loc.setWorldPosition(spawnPosition);
// reset rotation
loc.setLocalRotation(new Quaternionf());
character.saveComponent(loc);
}
Aggregations