Hi, I know this question has been asked (and solved) before, but I have had no luck with using previous solutions.
I’m fairly new to scripting in Unity, but I was doing okay until now… I just don’t understand this one thing.
I have a simple CharacterController move script and can move, turn, jump, etc. Only problem is, once I jump in a direction, I’m locked there. I have it set up to allow turning in mid-air, but I still cannot move on the Z axis.
I know about the apparent fix, removing “IsGrounded” but that has not worked for me.
Can anyone help me?
Thanks.
My script:
var speed : float = 6.0;
var jumpSpeed : float = 8.0;
var turnSpeed : float = 60;
var gravity : float = 20.0;
private var moveDirection : Vector3 = Vector3.zero;
function Update() {
var controller : CharacterController = GetComponent(CharacterController);
var turn: float = Input.GetAxis("Horizontal");
transform.Rotate(0, turn * turnSpeed * Time.deltaTime, 0);
if (controller.isGrounded) { // only move or jump if grounded
moveDirection = transform.forward * Input.GetAxis("Vertical") * speed;
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
}
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
controller.Move(moveDirection * Time.deltaTime);
}