Search in sources :

Example 1 with FirstPersonHeldItemMountPointComponent

use of org.terasology.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();
        CharacterComponent charComp = charEntity.getComponent(CharacterComponent.class);
        if (charComp != null) {
            Vector3f dir = player.getViewDirection();
            float maxDist = charComp.interactionRange;
            FirstPersonHeldItemMountPointComponent heldItemMountPoint = player.getCameraEntity().getComponent(FirstPersonHeldItemMountPointComponent.class);
            if (heldItemMountPoint != null && heldItemMountPoint.isTracked()) {
                maxDist = heldItemMountPoint.translate.length() + 0.25f;
                dir = 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.logic.players.PlayerTargetChangedEvent) Vector3f(org.terasology.math.geom.Vector3f) CharacterComponent(org.terasology.logic.characters.CharacterComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) FirstPersonHeldItemMountPointComponent(org.terasology.logic.players.FirstPersonHeldItemMountPointComponent)

Aggregations

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