RagdollUtilityDemo.cs 934 B

12345678910111213141516171819202122232425262728293031323334
  1. using UnityEngine;
  2. using System.Collections;
  3. using RootMotion.FinalIK;
  4. namespace RootMotion.Demos {
  5. // Demonstrating the use of RagdollUtility.cs.
  6. public class RagdollUtilityDemo : MonoBehaviour {
  7. public RagdollUtility ragdollUtility;
  8. public Transform root;
  9. public Rigidbody pelvis;
  10. void OnGUI() {
  11. GUILayout.Label(" Press R to switch to ragdoll. " +
  12. "\n Weigh in one of the FBBIK effectors to make kinematic changes to the ragdoll pose." +
  13. "\n A to blend back to animation");
  14. }
  15. void Update() {
  16. if (Input.GetKeyDown(KeyCode.R)) ragdollUtility.EnableRagdoll();
  17. if (Input.GetKeyDown(KeyCode.A)) {
  18. // Move the root of the character to where the pelvis is without moving the ragdoll
  19. Vector3 toPelvis = pelvis.position - root.position;
  20. root.position += toPelvis;
  21. pelvis.transform.position -= toPelvis;
  22. ragdollUtility.DisableRagdoll();
  23. }
  24. }
  25. }
  26. }