1
0
mirror of synced 2024-12-03 18:27:16 +01:00
WACVR/Assets/Script/Controller/HandFollowManager.cs
2022-10-16 15:42:49 +02:00

54 lines
1.5 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HandFollowManager : MonoBehaviour
{
public GameObject Target;
public Transform Center;
public Config.handStabilization Mode;
public float VelocityThreshold = 0.1f;
private Rigidbody TargetRigidbody;
private Vector3 previousPosition;
private void Start()
{
TargetRigidbody = Target.GetComponent<Rigidbody>();
ConfigManager.onConfigChanged += ApplyConfig;
ConfigManager.EnsureInitialization();
ApplyConfig();
}
private void ApplyConfig()
{
VelocityThreshold = ConfigManager.config.HandStabilVelocity;
Mode = ConfigManager.config.HandStabilizationMode;
}
private void VelocityTracking()
{
Vector3 velocity = (Target.transform.position - previousPosition) / Time.deltaTime;
if (velocity.magnitude > VelocityThreshold)
{
transform.position = Target.transform.position;
}
previousPosition = Target.transform.position;
}
private void Update()
{
gameObject.transform.localScale = Target.transform.localScale;
}
private void FixedUpdate()
{
switch (Mode)
{
case Config.handStabilization.Velocity:
VelocityTracking();
break;
case Config.handStabilization.None:
transform.position = Target.transform.position;
break;
}
}
}