Lock the Character in only horizontal direction

in unit standard assets there is a character controller asset , i want to lock the character movement in the horizontal direction… like in the 2d platform games , how can i achieve it… , can anyone please help me with that

1 Answer

1

Hi.

Search this part in the CharacterMotor.js:

function Update () {
	if (!useFixedUpdate)
		UpdateFunction();
}

Change this part like so:

function Update () {
transform.position.z=0;
	if (!useFixedUpdate)
		UpdateFunction();
}

Your Character should now be locked to the 0-Koordinate on z-Axis.

Now it can only move in the other 2 remaining directions: x and y (up/down and right/left)

This should work fine. If not, report the error or what is still wrong with the movment in any way. I hope this will help you =)

Ah ok so thats no problem =) just create a new javascript and attach it to your character: #pragma strict funktion Update () { transform.position.x=0; } This should do the trick.