add physics hand
This commit is contained in:
@@ -8,14 +8,17 @@ public class HandFollowManager : MonoBehaviour
|
||||
public Transform Center;
|
||||
public CEnum.handStabilization Mode;
|
||||
public float VelocityThreshold = 0.1f;
|
||||
private Rigidbody currentRigidbody;
|
||||
private Rigidbody TargetRigidbody;
|
||||
private Vector3 previousPosition;
|
||||
|
||||
|
||||
private void Start()
|
||||
{
|
||||
TargetRigidbody = Target.GetComponent<Rigidbody>();
|
||||
currentRigidbody = GetComponent<Rigidbody>();
|
||||
|
||||
var modeWidget = ConfigManager.GetConfigPanelWidget("HandStabilization");
|
||||
var modeWidget = ConfigManager.GetConfigPanelWidget("HandTrackingMode");
|
||||
var threshWidget = ConfigManager.GetConfigPanelWidget("Threshold");
|
||||
|
||||
var modeDropdown = modeWidget.GetComponent<TMP_Dropdown>();
|
||||
@@ -24,6 +27,18 @@ public class HandFollowManager : MonoBehaviour
|
||||
modeDropdown.onValueChanged.AddListener((int value) => {
|
||||
VelocityThreshold = ConfigManager.config.HandStabilVelocity;
|
||||
Mode = (CEnum.handStabilization)value;
|
||||
switch (Mode)
|
||||
{
|
||||
case CEnum.handStabilization.None:
|
||||
currentRigidbody.isKinematic = true;
|
||||
break;
|
||||
case CEnum.handStabilization.Physics:
|
||||
currentRigidbody.isKinematic = false;
|
||||
break;
|
||||
case CEnum.handStabilization.Velocity:
|
||||
currentRigidbody.isKinematic = true;
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
threshSlider.onValueChanged.AddListener((float value) => {
|
||||
@@ -40,9 +55,21 @@ public class HandFollowManager : MonoBehaviour
|
||||
if (velocity.magnitude > VelocityThreshold)
|
||||
{
|
||||
transform.position = Target.transform.position;
|
||||
//PhysicsMove(Target.transform);
|
||||
}
|
||||
previousPosition = Target.transform.position;
|
||||
}
|
||||
|
||||
private void PhysicsMove(Transform targetTransform)
|
||||
{
|
||||
currentRigidbody.velocity = (targetTransform.position - transform.position) / Time.fixedDeltaTime;
|
||||
|
||||
Quaternion rotationDelta = targetTransform.rotation * Quaternion.Inverse(transform.rotation);
|
||||
rotationDelta.ToAngleAxis(out float angle, out Vector3 axis);
|
||||
|
||||
Vector3 rotationDeltaInDegrees = angle * axis;
|
||||
currentRigidbody.angularVelocity = rotationDeltaInDegrees * Mathf.Deg2Rad / Time.fixedDeltaTime;
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
gameObject.transform.localScale = Target.transform.localScale;
|
||||
@@ -52,12 +79,16 @@ public class HandFollowManager : MonoBehaviour
|
||||
{
|
||||
switch (Mode)
|
||||
{
|
||||
case CEnum.handStabilization.Velocity:
|
||||
VelocityTracking();
|
||||
break;
|
||||
case CEnum.handStabilization.None:
|
||||
transform.position = Target.transform.position;
|
||||
break;
|
||||
case CEnum.handStabilization.Physics:
|
||||
//transform.position = Target.transform.position;
|
||||
PhysicsMove(Target.transform);
|
||||
break;
|
||||
case CEnum.handStabilization.Velocity:
|
||||
VelocityTracking();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user