Hi all! I’ve scripted a pretty simple third person script, however, in the cases that I might want my player to run up walls, I’d prefer not to move on the Y plane. How would I go about doing that from what I already have?
Control.js
#pragma strict
var moveSpeed : float = 18.0;
private var controller : CharacterController;
private var isMove : boolean = true;
private var moveDirection : Vector3 = Vector3.zero;
function Awake(){
controller = GetComponent(CharacterController);
}
function Update() {
UpdateMoveDirection();
if(!controller.isGrounded){
SetGravity();
}
}
function UpdateMoveDirection(){
var forward : Vector3 = Camera.main.transform.TransformDirection(Vector3.forward);
forward.y = 0;
forward = forward.normalized;
var right : Vector3 = Vector3(forward.z, 0, -forward.x);
var vertical : float = Input.GetAxis("Vertical");
var horizontal : float = Input.GetAxis("Horizontal");
var targetDirection : Vector3 = horizontal * right + vertical * forward;
targetDirection *= moveSpeed;
moveDirection.x = targetDirection.x;
moveDirection.z = targetDirection.z;
if(targetDirection != Vector3.zero){
var rotation0 = transform.rotation;
rotation0.SetLookRotation(new Vector3(moveDirection.x,0,moveDirection.z) * Time.deltaTime / 2);
transform.localRotation = rotation0;
}
if(isMove)
controller.Move(moveDirection * Time.deltaTime);
}
@script RequireComponent(Rigidbody)
@script RequireComponent(CharacterController)