1
This commit is contained in:
49
Assets/BITKit/Unity/Scripts/Physics/PhysicsBasedAnimation.cs
Normal file
49
Assets/BITKit/Unity/Scripts/Physics/PhysicsBasedAnimation.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITKit.Physics
|
||||
{
|
||||
[Serializable]
|
||||
public class JointConfigure
|
||||
{
|
||||
public Transform animate;
|
||||
public ConfigurableJoint joint;
|
||||
public Quaternion InitialRotation { get; set; }
|
||||
}
|
||||
public class PhysicsBasedAnimation : MonoBehaviour
|
||||
{
|
||||
[Range(0, 1)] public float Blend;
|
||||
[SerializeField] private JointConfigure[] jointConfigures;
|
||||
[SerializeField] private float positionSpring;
|
||||
[SerializeField] private float positionDamper;
|
||||
[SerializeField] private float maximumForce;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
foreach (var x in jointConfigures)
|
||||
{
|
||||
x.InitialRotation=x.animate.localRotation;
|
||||
}
|
||||
}
|
||||
private void FixedUpdate()
|
||||
{
|
||||
//var spring = Mathf.Lerp(Blend,0,angularSprint);
|
||||
var drive = new JointDrive
|
||||
{
|
||||
positionDamper = positionDamper,
|
||||
positionSpring = positionSpring,
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user