SDM_LethalCompany_Mod/ScarletMansion/ScarletMansion/GamePatch/Components/ScarletFrame.cs
LadyAliceMargatroid e9152782aa Added treasure rooms
Added keyslot compatibility
Frames look at when you look away
Fixed snow globes
2024-08-04 22:02:12 -07:00

45 lines
1.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using Unity.Netcode;
using GameNetcodeStuff;
namespace ScarletMansion.GamePatch.Components {
public class ScarletFrame : MonoBehaviour {
public float visualUpdate = 0.2f;
private float visualUpdateCurrent = 0f;
void Start(){
visualUpdateCurrent = UnityEngine.Random.value * visualUpdate;
}
void Update() {
visualUpdateCurrent += Time.deltaTime;
if (visualUpdateCurrent > visualUpdate) {
LookAtLocalPlayer();
visualUpdateCurrent = 0f;
}
}
void LookAtLocalPlayer(){
var localPlayer = StartOfRound.Instance.localPlayerController;
if (localPlayer && !localPlayer.isPlayerDead) {
var direction = localPlayer.transform.position - transform.position;
direction.y = 0f;
direction = direction.normalized;
var playerFacing = -localPlayer.gameplayCamera.transform.forward;
// only face player when player looking away
if (Vector3.Dot(playerFacing, direction) < 0.25f) {
transform.rotation = Quaternion.LookRotation(direction);
}
}
}
}
}