This commit is contained in:
CortexCore
2023-10-24 23:37:59 +08:00
parent 325f63d6bc
commit 3e39e627bc
388 changed files with 29043 additions and 889 deletions

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using BITKit.Core.Tuple;
using UnityEngine;
namespace BITKit.Physics
@@ -19,6 +20,10 @@ namespace BITKit.Physics
[SerializeField] private float positionSpring;
[SerializeField] private float positionDamper;
[SerializeField] private float maximumForce;
[SerializeField] private Optional<UnityTuple<Rigidbody, Transform>> rootSync;
[SerializeField] private Optional<ConfigurableJointMotion> overrideMotion;
[SerializeField] private Optional<ConfigurableJointMotion> overrideAngularMotion;
private void Start()
{
@@ -33,16 +38,46 @@ namespace BITKit.Physics
var drive = new JointDrive
{
positionDamper = positionDamper,
positionSpring = positionSpring,
positionSpring =Mathf.Lerp(0,positionSpring,Blend),
maximumForce = maximumForce,
};
foreach (var jointConfigure in jointConfigures)
{
jointConfigure.joint.angularXDrive = drive;
jointConfigure.joint.angularYZDrive = drive;
jointConfigure.joint.targetRotation = Quaternion.Inverse(jointConfigure.animate.localRotation) *
jointConfigure.InitialRotation;
// jointConfigure.joint.targetRotation =
// Quaternion.Lerp(
// Quaternion.identity,
// Quaternion.Inverse(jointConfigure.animate.localRotation) * jointConfigure.InitialRotation,
// Blend
// );
jointConfigure.joint.targetRotation = Quaternion.Inverse(jointConfigure.animate.localRotation) *
jointConfigure.InitialRotation;
jointConfigure.joint.targetPosition = jointConfigure.animate.localPosition;
if (overrideAngularMotion.Allow)
{
jointConfigure.joint.angularXMotion = overrideAngularMotion.Value;
jointConfigure.joint.angularYMotion = overrideAngularMotion.Value;
jointConfigure.joint.angularZMotion = overrideAngularMotion.Value;
}
if (overrideMotion.Allow)
{
jointConfigure.joint.xMotion = overrideMotion.Value;
jointConfigure.joint.yMotion = overrideMotion.Value;
jointConfigure.joint.zMotion = overrideMotion.Value;
}
}
if (rootSync.Allow)
{
var root = rootSync.Value;
root.Item1.transform.localPosition = root.Item2.localPosition;
root.Item1.MoveRotation(root.Item2.rotation);
}
}
}