39 lines
1.4 KiB
C#
39 lines
1.4 KiB
C#
using RebootKit.Engine.Foundation;
|
|
using UnityEngine;
|
|
|
|
namespace RealityReboot.jelycho.game {
|
|
[RequireComponent(typeof(Rigidbody))]
|
|
[AddComponentMenu(GameConsts.k_AddComponentMenu + "Active Ragdoll/Bone")]
|
|
public class ActiveRagdollBone : MonoBehaviour {
|
|
public const float k_MaxHealth = 100.0f;
|
|
|
|
[SerializeField] Transform m_Source;
|
|
[SerializeField] Rigidbody m_Rigidbody;
|
|
[SerializeField] CharacterJoint m_CharacterJoint;
|
|
[SerializeField] ConfigurableJoint m_ConfigurableJoint;
|
|
|
|
[SerializeField] ConstsProperty<float> m_Torque = new(100.0f);
|
|
|
|
[Range(0.0f, k_MaxHealth)] public float health = k_MaxHealth;
|
|
|
|
public Rigidbody Rigidbody => m_Rigidbody;
|
|
|
|
void FixedUpdate() {
|
|
Quaternion targetRotation = m_Source.rotation;
|
|
Quaternion deltaRotation = targetRotation * Quaternion.Inverse(m_Rigidbody.rotation);
|
|
|
|
float strength = Mathf.Clamp01(health / k_MaxHealth);
|
|
|
|
Vector3 torque = m_Torque.Value * strength * new Vector3(deltaRotation.x, deltaRotation.y, deltaRotation.z);
|
|
// m_Rigidbody.AddTorque(torque);
|
|
|
|
// m_ConfigurableJoint.targetRotation = targetRotation * Quaternion.Inverse(m_Rigidbody.rotation);
|
|
}
|
|
|
|
void OnValidate() {
|
|
if (m_Rigidbody == null) {
|
|
m_Rigidbody = GetComponent<Rigidbody>();
|
|
}
|
|
}
|
|
}
|
|
} |