Ejemplo n.º 1
0
    /// <summary>
    /// teleports to the chosen destination, and takes care of footstep fx,
    /// fall damage, and teleport interval
    /// </summary>
    protected virtual void TeleportTo(Vector3 destination)
    {
        if (!enabled)
        {
            return;
        }

        // teleport to the chosen destination
        Vector3 prevPos = FPPlayer.Position.Get();

        FPPlayer.Position.Set(destination);
        FPPlayer.Stop.Send();

        // trigger a footstep effect
        if (VRFootFXHandler != null)
        {
            VRFootFXHandler.TryStep();
        }

        // trigger a fall impact if far enough down
        float fallDistance = (prevPos.y - (FPPlayer.Position.Get().y));

        if (fallDistance > FallImpactDistance)
        {
            FPPlayer.FallImpact.Send(fallDistance * 0.05f);                     // NOTE: this is just an approximation of the default UFPS fall damage sensitivity
        }
        // regulate minimum teleport interval
        m_NextAllowedTeleportTime = (Time.time + MinTeleportInterval);

        // notify external components that care about the camera snapping
        // to a new destination in a single frame
        SendMessage("OnCameraSnap", SendMessageOptions.DontRequireReceiver);
    }
Ejemplo n.º 2
0
    /// <summary>
    /// rotates the whole player body and OVR camera rig a set number of degrees
    /// to the left or right in one frame, and sends a Unity Message 'OnCameraSnap'.
    /// 'dir' must be either '-1' (LEFT) or '1' (RIGHT)
    /// </summary>
    protected virtual void DoSnapRotate(float dir)
    {
        if ((dir != LEFT) && (dir != RIGHT))
        {
            return;
        }

        Transform t = CenterEyeAnchor.root;

        t.eulerAngles = new Vector3(t.eulerAngles.x, t.eulerAngles.y + (SnapRotation.StepDegrees * dir), t.eulerAngles.z); // rotate OVR camera rig
        FPPlayer.Rotation.Set(new Vector2(FPPlayer.Rotation.Get().x, t.eulerAngles.y + (SnapRotation.StepDegrees * dir))); // rotate UFPS player hierarchy
        m_NextAllowedSnapRotateTime = (Time.time + SnapRotation.MinDelay);                                                 // enforce minimum snap rotate interval
        SendMessage("OnCameraSnap", SendMessageOptions.DontRequireReceiver);                                               // notify external components
        if (VRFootFXHandler != null)                                                                                       // try to play a footstep sound
        {
            VRFootFXHandler.TryStep();
        }
    }