1
This commit is contained in:
@@ -27,7 +27,10 @@ namespace BITKit
|
||||
break;
|
||||
}
|
||||
vector3 = collider.ClosestPoint(root.position + Vector3.up);
|
||||
return vector3.y == collider.bounds.center.y + collider.bounds.extents.y;
|
||||
var top = collider.bounds.center + collider.bounds.extents;
|
||||
return Mathf.Abs(vector3.y - top.y) <0.16f;
|
||||
//return vector3.y >= collider.bounds.center.y + collider.bounds.extents.y;
|
||||
//return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
26
Src/Unity/Scripts/Physics/JointBasedSync.cs
Normal file
26
Src/Unity/Scripts/Physics/JointBasedSync.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
11
Src/Unity/Scripts/Physics/JointBasedSync.cs.meta
Normal file
11
Src/Unity/Scripts/Physics/JointBasedSync.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f6fe23fca67cb7346a3c423d97c9e101
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
@@ -9,8 +10,22 @@ namespace BITKit
|
||||
public static async UniTask AddForceAtPositionAsync(this Rigidbody rigidbody, Vector3 force, Vector3 position,ForceMode forceMode=ForceMode.Force)
|
||||
{
|
||||
await UniTask.DelayFrame(8);
|
||||
if (rigidbody is not null)
|
||||
rigidbody.AddForceAtPosition(force, position,forceMode);
|
||||
try
|
||||
{
|
||||
rigidbody.AddForceAtPosition(force, position,forceMode);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user