Search in sources :

Example 1 with FirstPersonHeldItemMountPointComponent

use of org.terasology.engine.logic.players.FirstPersonHeldItemMountPointComponent in project Terasology by MovingBlocks.

the class PlayerTargetSystem method update.

@Override
public void update(float delta) {
    EntityRef charEntity = player.getCharacterEntity();
    if (charEntity.exists()) {
        Vector3f cameraPos = player.getViewPosition(new Vector3f());
        CharacterComponent charComp = charEntity.getComponent(CharacterComponent.class);
        if (charComp != null) {
            Vector3f dir = player.getViewDirection(new Vector3f());
            float maxDist = charComp.interactionRange;
            FirstPersonHeldItemMountPointComponent heldItemMountPoint = player.getCameraEntity().getComponent(FirstPersonHeldItemMountPointComponent.class);
            if (heldItemMountPoint != null && heldItemMountPoint.isTracked()) {
                maxDist = heldItemMountPoint.translate.length() + 0.25f;
                dir = new Vector3f(heldItemMountPoint.translate).normalize();
            }
            if (targetSystem.updateTarget(cameraPos, dir, maxDist)) {
                EntityRef oldTarget = targetSystem.getPreviousTarget();
                EntityRef newTarget = targetSystem.getTarget();
                charEntity.send(new PlayerTargetChangedEvent(oldTarget, newTarget));
            }
        }
    }
}
Also used : PlayerTargetChangedEvent(org.terasology.engine.logic.players.PlayerTargetChangedEvent) Vector3f(org.joml.Vector3f) CharacterComponent(org.terasology.engine.logic.characters.CharacterComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) FirstPersonHeldItemMountPointComponent(org.terasology.engine.logic.players.FirstPersonHeldItemMountPointComponent)

Aggregations

Vector3f (org.joml.Vector3f)1 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)1 CharacterComponent (org.terasology.engine.logic.characters.CharacterComponent)1 FirstPersonHeldItemMountPointComponent (org.terasology.engine.logic.players.FirstPersonHeldItemMountPointComponent)1 PlayerTargetChangedEvent (org.terasology.engine.logic.players.PlayerTargetChangedEvent)1