Skip to content

Commit

Permalink
Switch side when spectating headcam/3rd person and player changes lef…
Browse files Browse the repository at this point in the history
…t stance
  • Loading branch information
Lacyway committed May 31, 2024
1 parent 38a1dc5 commit c4e73cc
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions Fika.Core/Coop/FreeCamera/FreeCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using EFT;
using Fika.Core.Coop.Components;
using Fika.Core.Coop.Players;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
Expand All @@ -23,6 +24,7 @@ public class FreeCamera : MonoBehaviour
public bool IsActive = false;
private CoopPlayer CurrentPlayer;
private bool isFollowing = false;
private bool leftMode = false;
private bool disableInput = false;

private KeyCode forwardKey = KeyCode.W;
Expand Down Expand Up @@ -248,6 +250,17 @@ protected void Update()

if (isFollowing)
{
if (CurrentPlayer != null)
{
if (CurrentPlayer.MovementContext.LeftStanceEnabled && !leftMode)
{
SetLeftShoulderMode(true);
}
else if (!CurrentPlayer.MovementContext.LeftStanceEnabled && leftMode)
{
SetLeftShoulderMode(false);
}
}
return;
}

Expand Down Expand Up @@ -323,6 +336,36 @@ protected void Update()
transform.localEulerAngles = new Vector3(newRotationY, newRotationX, 0f);
}

private void SetLeftShoulderMode(bool enabled)
{
if (enabled)
{
// Use different coordinates for headcam
if (transform.localPosition.z == -0.17f)
{
transform.localPosition = new(transform.localPosition.x, transform.localPosition.y, -transform.localPosition.z);
}
else
{
transform.localPosition = new(-transform.localPosition.x, transform.localPosition.y, transform.localPosition.z);
}
leftMode = true;
}
else
{
// Use different coordinates for headcam
if (transform.localPosition.z == 0.17f)
{
transform.localPosition = new(transform.localPosition.x, transform.localPosition.y, -transform.localPosition.z);
}
else
{
transform.localPosition = new(-transform.localPosition.x, transform.localPosition.y, transform.localPosition.z);
}
leftMode = false;
}
}

private void ToggleVision()
{
NightVision nightVision = CameraClass.Instance.NightVision;
Expand Down Expand Up @@ -353,6 +396,7 @@ public void JumpToPlayer()
if (isFollowing)
{
isFollowing = false;
leftMode = false;
transform.parent = null;
}
}
Expand Down Expand Up @@ -425,6 +469,7 @@ public void SetActive(bool status)

IsActive = status;
isFollowing = false;
leftMode = false;
transform.parent = null;
}

Expand Down

0 comments on commit c4e73cc

Please sign in to comment.