Search code examples
unity-game-engine2dragdoll

2D Ragdoll movement in unity


I tried make a Ragdoll game with my brother but the problem is that we try make a Ragdoll movement and we can make a movement but when we try this movement on the Ragdoll It just goes pretty normal. we know we need bones and things like that but we don't know how can we make A script like that. we don't want see tutorials on YouTube we want to make a script that how We want to be. Anyone have any idea how we can do that? Oh and I know when I wrote this there were some spelling errors in the above code so sorry for that. here's our script:

    using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Movement : MonoBehaviour
{
    // Start is called before the first frame update
    public float force;
    public Rigidbody2D body;

    public Leg[] legs;

    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKey(KeyCode.D))
        {

            Vector2 vec = Vector2.right * force;
            body.AddForce(vec);

            foreach (Leg leg in legs)
            {
                leg.Walk();
            }

        }


    }
}

[System.Serializable]
public class Leg
{
    public Rigidbody2D bone;
    public float walkRotation;
    public float force;

    public void Walk()
    {
        bone.MoveRotation(Mathf.LerpAngle(bone.rotation, walkRotation, force * Time.deltaTime));
    }
}

Solution

  • Use animations for different movements it will save you a lot of time. If you want the Rag doll effect enable it after the Player dies. So, in animations you should check blend trees if you want different animations for different speeds or locations etc. All game characters move as one Object and the rest is done in Animations. It is much simpler and efficient.