- Home /
Question by
RandomBinaries · Sep 28, 2012 at 10:20 PM ·
javascriptmovementcharacter controllermathf.clamp
Mathf.Clamp Problem with Character Controller Script
Can anyone help me please as I am trying to use the character controller script to move my character whilst restricting its movement beyond the scope of the camera. Help much appreciated.
var speed : float = 0.01; private var moveDirection : Vector3 = Vector3.zero;
function Update() {
var controller : CharacterController = GetComponent(CharacterController);
moveDirection = Vector3(0,Input.GetAxis("Vertical"),0);
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
controller.Move(moveDirection * Time.deltaTime);
Debug.Log(moveDirection); moveDirection.z = Mathf.Clamp(moveDirection.z, -1.0, 6.0);
}
Comment