Easy Active Ragdoll Tutorial, Unity.

Поділитися
Вставка
  • Опубліковано 23 лис 2024

КОМЕНТАРІ • 5

  • @tituskizer6478
    @tituskizer6478  7 місяців тому

    SCRIPTS:
    public class RagdollAnimation : MonoBehaviour
    {
    public Transform ReflectLimb;
    public bool NiceMirror;
    ConfigurableJoint Config;
    // Start is called before the first frame update
    void Start()
    {
    Config = GetComponent();
    }
    // Update is called once per frame
    void Update()
    {
    if (!NiceMirror)
    {
    Config.targetRotation = ReflectLimb.rotation;
    }
    else
    {
    Config.targetRotation = Quaternion.Inverse(ReflectLimb.rotation);
    }
    }
    }
    public class RagDollControler : MonoBehaviour
    {
    public Animator Actim;
    public float speed;
    public float strafeSpeed;
    public float jumpForce;
    public Rigidbody hips;
    public bool isGrounded;
    // Start is called before the first frame update
    void Start()
    {
    hips = GetComponent();
    }
    private void FixedUpdate()
    {
    if (Input.GetKey(KeyCode.W))
    {
    hips.AddForce(hips.transform.forward * speed);
    Actim.SetBool("isWalking", true);
    }
    else
    {
    Actim.SetBool("isWalking", false);
    }
    if (Input.GetKey(KeyCode.A))
    {
    hips.AddForce(-hips.transform.right * speed);
    Actim.SetBool("isWalkingLeft", true);
    }
    else if (!Input.GetKey(KeyCode.A))
    {
    Actim.SetBool("isWalkingLeft", false);
    }
    if (Input.GetKey(KeyCode.S))
    {
    hips.AddForce(-hips.transform.forward * speed);
    Actim.SetBool("isWalkingBackwards", true);
    }
    else if (!Input.GetKey(KeyCode.S))
    {
    Actim.SetBool("isWalkingBackwards", false);
    }
    if (Input.GetKey(KeyCode.D))
    {
    hips.AddForce(hips.transform.right * speed);
    Actim.SetBool("isWalkingRight", true);
    }
    else if (!Input.GetKey(KeyCode.D))
    {
    Actim.SetBool("isWalkingRight", false);
    }
    if (Input.GetAxis("Jump") > 0)
    {
    if (isGrounded)
    {
    hips.AddForce(new Vector3(0, jumpForce, 0));
    isGrounded = false;
    Actim.SetBool("isJumping", true);
    }
    }
    }
    }
    public class Ragdolljumpassist : MonoBehaviour
    {
    public Animator Actimm;
    public RagDollControler ragdollControler;
    private void Start()
    {
    ragdollControler = GameObject.FindObjectOfType().GetComponent();
    }
    private void OnCollisionEnter(Collision collision)
    {
    ragdollControler.isGrounded = true;
    Actimm.SetBool("isJumping", false);
    }
    }

  • @Socks_X1
    @Socks_X1 6 днів тому

    at 3:56 how did you get him to have gravity and drop? i cant seem to get him to even sway, it says the bones are moving but he just stands still

    • @tituskizer6478
      @tituskizer6478  6 днів тому

      I see. I've never experienced that before, please tell me what you did step by step so I can pinpoint the problem.

  • @sirPokerick
    @sirPokerick 5 місяців тому

    Nice! Can you do one for mixamo animations?

    • @tituskizer6478
      @tituskizer6478  4 місяці тому

      Thanks! Well, I haven't tried it with Mixamo animations but I don't believe it should make any difference. But I must warn you that as you saw in the video you have to rotate the limbs after assigning the Ragdoll Animation script for them to move in the correct directions, and if you add the script to any other bones aside from the upper arms, upper legs, spine and neck you may have to spend a lot of time figuring out which way to rotate them for the correct result, but it is possible. Hope that helps and thanks for the comment!