Rare Rotation on Player, please help

Hey guys, im new in unity development, actually working on a project with a friend of mine, i was told to make a third person camera for the player, and i found some tutorial to make it… however after done, all perfect (walking, running, zoom in, zoom out, rotation of camera,etc) except the rotation, when i press the Horizontal buttons (left, right, D or A), the model actually rotates but apparently dont rotate on his own axis but another one, i dont know why. Actually that is a part of the proble, the other one is that when i rotate the model, the character controller goes crazy because when i try to go up on a mountain the model walks below the terrain, it is like the character controller goes up and the model stays where it was… dont know what to do, please help. The tutorial i used was this one > http://www.unitylabs.net/tutorials/character-controllers/third-person-character-controller < It has two parts, the characte controller for the model and the camera controller.

PD: Sorry Bad english :stuck_out_tongue:

Hi, welcome to the forum!

Can you post both of the scripts that are giving you these problems?

Hi, these are the scripts, this one is for moving and animating:

private var walkSpeed : float = 5.0; 
private var gravity = 100.0;
 private var moveDirection : Vector3 = Vector3.zero;
 private var charController : CharacterController;
 
function Start() 
{
	charController = GetComponent(CharacterController); 
	animation.wrapMode = WrapMode.Loop;
 }
 
function Update () 
{ 
	if(charController.isGrounded == true) 
	{ 
		if(Input.GetAxis("Vertical") > .1) 
		{ 
			if(Input.GetButton("Run")) 
				{ 
					animation.CrossFade("correr"); 
					animation["correr"].speed = 2;
					walkSpeed = 15; 
				}
		else
			 { 
				 animation["caminar"].speed = 1; 
				animation.CrossFade("caminar");
				 walkSpeed = 5;
			 } 
		}
		else if(Input.GetAxis("Vertical") < -.1) 
		{ 
			animation["caminar"].speed = -1;
			 animation.CrossFade("caminar");
			 walkSpeed = 3; 
		}
	else 
		{
			animation.CrossFade("idle");
		 }
		 
	// Create an animation cycle for when the character is turning on the spot 
	if(Input.GetAxis("Horizontal")  !Input.GetAxis("Vertical")) 
		{ 
			animation.CrossFade("caminar"); 
		}
		transform.eulerAngles.y += Input.GetAxis("Horizontal") ;
		 // Calculate the movement direction (forward motion) 
		moveDirection = Vector3(0,0, Input.GetAxis("Vertical"));
		 moveDirection = transform.TransformDirection(moveDirection);
	}
	moveDirection.y -= gravity * Time.deltaTime;
	 charController.Move(moveDirection * (Time.deltaTime * walkSpeed));
}

This one is for the camera, i think the problem is in the above code but will post it too.

var target : Transform;
private var distance = 15.0;
private var xSpeed = 250.0;
private var ySpeed = 120.0;
private var yMinLimit = 0;
private var yMaxLimit = 80;
private var cameraMode = "third";
private var zoomMinLimit = 5;
private var zoomMaxLimit = 25;

private var x = 0.0;
private var y = 0.0;

function Start()
{
	var angles = transform.eulerAngles;
	x = angles.y;
	y = angles.x;
}

function LateUpdate()
{

	if(cameraMode == "third")
	{
	
		var characterRotation = target.transform.eulerAngles.y;
		var cameraRotation = transform.eulerAngles.y;
	
		if(Input.GetButton("CameraZoomIn")  distance > zoomMinLimit) 
		{
			distance = distance -1 / (xSpeed * 0.02); 
		} 
		if(Input.GetButton("CameraZoomOut")  distance < zoomMaxLimit) 
		{ 
			distance = distance +1 / (xSpeed * 0.02); 
		}
		x += Input.GetAxis("CameraX") * xSpeed * 0.02;
		y -= Input.GetAxis("CameraY") * ySpeed * 0.02;
		y = ClampAngle(y, yMinLimit, yMaxLimit);
		
		if(Input.GetAxis("Vertical") || Input.GetAxis("Horizontal")) 
		{
		rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(y, characterRotation, 0), Time.deltaTime * 3); 
		position = rotation * Vector3(0.0, 0.0, -distance) + target.position; 
		x = characterRotation;
		}
		else 
		{
		rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(y, x, 0), Time.deltaTime * 3); 
		position = rotation * Vector3(0.0, 0.0, -distance) + target.position;
		}
	
		
		transform.rotation = rotation;
		transform.position = position;
	}
	
	
	
	
	
	else
	{
	
	}


}

static function ClampAngle (angle : float, min : float, max : float)
{
	if (angle < -360) 
	{ 
		angle += 360;
	} 
	if (angle > 360) 
	{ 
		angle -= 360; 
	} 
	return Mathf.Clamp (angle, min, max);
}