Ragdoll player character jumping unexpectedly when moved

Hi guys,

I made my player character into a ragdoll with the rag doll wizard, and the character also has a Character Controller component. When I try to test my game, the character can turn just fine using the keyboard or mouse. However, jumping (space) and moving forwards or backwards results in a strange behavior: the character’s transform.y increases dramatically as long as a movement key is pressed, with the problem happening less noticeably when jumping. Once the player stops pressing the relevant key or moving their gamepad’s left stick, the character floats downwards at a really slow, barely-notcable rate. This only started when I added a ragdoll component to my character, and here is my player movement script:

`
var speed = 3.0;
var rotateSpeed = 3.0;
var jumpSpeed: float = 1.0;
var gravity: float = 10.0; // gravity acceleration

private var vSpeed: float = 0; // store vertical speed in a separate variable
private var controller : CharacterController;
private var locked = false;
private var attacker : GameObject;

function Update ()
{
controller = GetComponent(CharacterController);

// Rotate around y - axis
transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);

if (!locked)
{
	// Move forward / backward
	// Move forward / backward
    var curSpeed = speed * Input.GetAxis ("Vertical");
    var moveDir = transform.forward * curSpeed;

	// Jump code
    if (controller.isGrounded)
    {
     // if character is grounded...
        vSpeed = 0; // its vert speed is zero
        if (Input.GetButtonDown("Jump"))
        { // but if jump pressed, set it to jumpSpeed
            vSpeed = jumpSpeed;
        }
    }
    // apply gravity acceleration
    vSpeed -= gravity * Time.deltaTime;
    moveDir.y = vSpeed; // include vSpeed in  moveDir
    // moveDir * Time.deltaTime is the displacement since last frame
    controller.Move(moveDir * Time.deltaTime);
}

else
{
	controller.Transform = attacker.transform;
}

// Animate character
if (Input.GetAxis("Vertical") > 0.1 || Input.GetAxis("Horizontal") > 0.1 || Input.GetAxis("Vertical") < -0.1 || Input.GetAxis("Horizontal") < -0.1)
       animation.CrossFade("run");
       else
       {
       animation.CrossFade("idle");
       }
}

function LockedInJaws (stuckPos : Vector3, sender : GameObject) 
{
	locked = true;
	// animation.CrossFade("buttstomp", 0.2);
	/*
	var playerController : ThirdPersonController = GetComponent(ThirdPersonController);
	while(!playerController.IsGrounded())
	{
		yield;	
	}
	*/
	transform.Translate(stuckPos, Space.Self);
	attacker = sender;
	
	Debug.Log("Player slammed, make the player move with the dog's head");
	// animation.Blend("buttstomp", 0, 0);
}

@script RequireComponent(CharacterController)
`

Why would my ragdoll component cause such behavior?

MachCUBED

This is caused by the rigidbodies in your ragdoll limbs colliding with your characterController collider or capsule collider. Toggling isKinematic to false on ragdoll limbs isn’t enough to fix this. You need to also toggle detectCollisions on each ragdoll rigidboy as well. I use something like this to adjust each ragdoll rigidbody:

public Rigidbody playerRigidbody;

void setKinematic(bool newValue)
{
    
    		//Get an array of components that are of type Rigidbody
    		Component[] components=GetComponentsInChildren(typeof(Rigidbody));
    
    		//For each of the components in the array, treat the component as a Rigidbody and set its isKinematic and detectCollisions property
    		foreach (Component c in components)
    		{
    			(c as Rigidbody).isKinematic=newValue;
    			(c as Rigidbody).detectCollisions=!newValue;
    		}
    
    		//Sets PLAYER rigid body as opposite
    		playerRigidbody.isKinematic = !newValue;
    		playerRigidbody.detectCollisions = newValue;
    
}

playerRigidbody is a public Transform of my player.