This commit is contained in:
CortexCore
2024-03-31 23:31:00 +08:00
parent e179d2eb53
commit b7b89ee71a
641 changed files with 31286 additions and 22134 deletions

View File

@@ -26,10 +26,12 @@ namespace BITKit.Physics
[Range(0, 1)] public float Blend;
[SerializeField] public bool allowFixedJoints;
[SerializeField] public bool allowGravity;
[SerializeField] public bool disablePhysics;
[Header(Constant.Header.Components)]
[SerializeField] private JointConfigure[] fixedJointConfigures;
[SerializeField] private JointConfigure[] jointConfigures;
[SerializeField] public JointConfigure[] fixedJointConfigures;
[SerializeField] public JointConfigure[] jointConfigures;
[Header(Constant.Header.Settings)]
[SerializeField] private float positionSpring;
@@ -83,7 +85,20 @@ namespace BITKit.Physics
private void FixedUpdate()
{
allowFixedJoint.SetElements(this,allowFixedJoints);
if (disablePhysics && allowFixedJoints)
{
foreach (var x in jointConfigures)
{
var jointTransform = x.joint.transform;
jointTransform.localPosition = x.animate.localPosition;
jointTransform.localRotation = x.animate.localRotation;
x.Rigidbody.isKinematic = true;
x.Rigidbody.useGravity = false;
}
return;
}
allowFixedJoint.SetElements(1,allowFixedJoints);
allowPhysicsAnimation.SetElements(this,Blend is not 0);
//var spring = Mathf.Lerp(Blend,0,angularSprint);
@@ -93,15 +108,41 @@ namespace BITKit.Physics
positionSpring =Mathf.Lerp(0,positionSpring,Blend),
maximumForce = maximumForce,
};
var emptyDrive = new JointDrive
{
positionDamper = 0,
positionSpring = 0,
maximumForce = 0,
};
var blendTorqueForce = Mathf.Lerp(0,this.torqueForce,Blend);
foreach (var jointConfigure in jointConfigures)
{
jointConfigure.joint.angularXDrive = drive;
jointConfigure.joint.angularYZDrive = drive;
jointConfigure.joint.xDrive = drive;
jointConfigure.joint.yDrive = drive;
jointConfigure.joint.zDrive = drive;
if (Blend is not 0)
{
jointConfigure.joint.angularXDrive = drive;
jointConfigure.joint.angularYZDrive = drive;
}
else
{
jointConfigure.joint.angularXDrive = emptyDrive;
jointConfigure.joint.angularYZDrive = emptyDrive;
}
if (allowGravity is false)
{
jointConfigure.joint.xDrive = drive;
jointConfigure.joint.yDrive = drive;
jointConfigure.joint.zDrive = drive;
}
else
{
jointConfigure.joint.xDrive = emptyDrive;
jointConfigure.joint.yDrive = emptyDrive;
jointConfigure.joint.zDrive = emptyDrive;
}
jointConfigure.joint.targetRotation =
Quaternion.Lerp(
@@ -139,7 +180,7 @@ namespace BITKit.Physics
// jointConfigure.Rigidbody.AddForce(
// jointConfigure.animate.localPosition - jointConfigure.Rigidbody.position,ForceMode.VelocityChange
// );
jointConfigure.Rigidbody.useGravity =Blend is 0;
jointConfigure.Rigidbody.useGravity = allowGravity;
//jointConfigure.Rigidbody.MoveRotation(jointConfigure.animate.rotation);
}