Ragdoll draging

Im using this code to drag the ragdoll around the screen

var spring = 100.0;
var damper = 5.0;
var drag = 10.0;
var angularDrag = 5.0;
var distance = 0.1;
var attachToCenterOfMass = false;

private var springJoint : SpringJoint;

function Update ()
{
	var layerMask = 1 << 8;
	layerMask = ~layerMask;
	// Make sure the user pressed the mouse down
	if (!Input.GetMouseButtonDown (0))
		return;

	var mainCamera = FindCamera();
		
	// We need to actually hit an object
	var hit : RaycastHit;
	if (!Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition),  hit, 100, layerMask))
		return;
	// We need to hit a rigidbody that is not kinematic
	if (!hit.rigidbody || hit.rigidbody.isKinematic)
		return;
	// Don't affect anything with name "Mine(Clone)", the name of everything that should be
	// ignored (to prevent mine stacking).
	if (hit.transform.name == "Mine(Clone)")
		return;
	
	if (!springJoint)
	{
		var go = new GameObject("Rigidbody dragger");
		body = go.AddComponent ("Rigidbody");
		springJoint = go.AddComponent ("SpringJoint");
		body.isKinematic = true;
	}
	
	springJoint.transform.position = hit.point;
	if (attachToCenterOfMass)
	{
		var anchor = transform.TransformDirection(hit.rigidbody.centerOfMass) + hit.rigidbody.transform.position;
		anchor = springJoint.transform.InverseTransformPoint(anchor);
		springJoint.anchor = anchor;
	}
	else
	{
		springJoint.anchor = Vector3.zero;
	}
	
	springJoint.spring = spring;
	springJoint.damper = damper;
	springJoint.maxDistance = distance;
	springJoint.connectedBody = hit.rigidbody;
	
	StartCoroutine ("DragObject", hit.distance);
}

function DragObject (distance : float)
{
	var oldDrag = springJoint.connectedBody.drag;
	var oldAngularDrag = springJoint.connectedBody.angularDrag;
	springJoint.connectedBody.drag = drag;
	springJoint.connectedBody.angularDrag = angularDrag;
	var mainCamera = FindCamera();
	while (Input.GetMouseButton (0))
	{
		var ray = mainCamera.ScreenPointToRay (Input.mousePosition);
		springJoint.transform.position = ray.GetPoint(distance);
		yield;
	}
	if (springJoint.connectedBody)
	{
		springJoint.connectedBody.drag = oldDrag;
		springJoint.connectedBody.angularDrag = oldAngularDrag;
		springJoint.connectedBody = null;
	}
}

function FindCamera ()
{
	if (camera)
		return camera;
	else
		return Camera.main;
}

i get this:
Assets/_Scripts/RagdollMode1.js(37,22): BCE0019: ‘isKinematic’ is not a member of ‘UnityEngine.Component’.

Is there a list of new API’s somehere?

Thanks

isKinematic is not a member of Component, it’s a member of rigidbody so you need to do an explicit type cast (to rigidbody).

Im sorry, what exactly do you mean. I don’t quite understand you mean.

Look at this part of your code:

if (!springJoint)
{
   var go = new GameObject("Rigidbody dragger");
   body = go.AddComponent ("Rigidbody");
   springJoint = go.AddComponent ("SpringJoint");
   body.isKinematic = true;
}

The problem is that AddComponent returns a Component data type, so body is of type Component it is not of type rigidbody. And as I mentioned, isKinematic is a member of rigidbody and not Component so you need to change your code up a bit. For example:

if (!springJoint)
{
   var go = new GameObject("Rigidbody dragger");
   body = go.AddComponent ("Rigidbody");
   springJoint = go.AddComponent ("SpringJoint");
   go.rigidbody.isKinematic = true;
}

This works quite well, but I’m wondering if there’s a way to cement the bottom of the object to the ground so that it doesn’t tumble, but when collides with other objects, bounces off them without falling over?

Take the shape of a cube (rectangular) that is tall. Any way of doing this?
Should i be using a Rigidbody?

Thanks

Check out this thread, which shows how to stabilise a rigidbody object by applying a pulling force just above and below the centre of mass.

Excellent, thank you I’ll look into this.