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

@@ -0,0 +1,26 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace MyNamespace
{
public class JointBasedSync : MonoBehaviour
{
[SerializeField] private ConfigurableJoint joint;
[SerializeField] private Transform animate;
private Quaternion _initialRotation;
private void Start()
{
_initialRotation = joint.transform.localRotation;
}
private void FixedUpdate()
{
//joint.targetPosition = animate.localPosition;
joint.targetRotation = Quaternion.Inverse(animate.localRotation) * _initialRotation;
}
}
}

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);
}
}
}

View File

@@ -17,5 +17,15 @@ namespace BITKit
catch(MissingReferenceException){}
}
public static async void Explosion(Vector3 position,float radius,LayerMask layerMask,float force)
{
await UniTask.DelayFrame(8);
foreach (var x in UnityEngine.Physics.OverlapSphere(position,radius,layerMask))
{
if(x.attachedRigidbody is null)continue;
x.attachedRigidbody.AddExplosionForce(force,position,radius);
//Debug.Log(x);
}
}
}
}