locking z position? making model free but still using joints?

hello,
Im making a horizontal controlling game,
I got a little problem here.
I tried to lock the character’s z position like this:

public var lockX : boolean;
public var lockY : boolean;
public var lockZ : boolean;
private var startPosition : Vector3;
function Start() {
	startPosition = transform.position;
}
function Update () {
	var position = transform.position;
	if(lockX  position.x != startPosition.x)
		transform.position.x = startPosition.x;
		
	if(lockY  position.y != startPosition.y)
		transform.position.y = startPosition.y;
		
	if(lockZ  position.z != startPosition.z)
		transform.position.z = startPosition.z;
}

but this way is really bad, ate about 20 fps number…

What is the best way to lock a transform’s z position but not using rigidbody?


The other question,
I need to make my character’s body “free” when dead but still using joints (sorry, I dont know how to express it better)
just like UDK 's dead characters,
Is that possible?

:face_with_spiral_eyes:

2nd Question: It’s called a Ragdoll. Check the Ragdoll Creator

yes it’s posible the ragdoll works perfectly. It’s dificult to make but it works.

And to lock the z position… i would use:

function Update(){

transform.position.z=0;

}

Why did u have wrote this long code?

I set the boolean variables because I want to make it able to choose if I want to lock x y or z.
and startPosition is the default position if I lock the item.