- Home /
Question by
iDerpCake · Mar 06, 2016 at 04:21 PM ·
c#movementcharactercontroller
Character Controller Movement
How can I make the character controller have a little or a controllable air speed? For Example: When I try to move in the air it moves the character a little, but not a as fast as regular walking speed. Code: using UnityEngine; using System.Collections;
public class MovementScript : MonoBehaviour {
public float speed = 6.0F;
public float sprintSpeed = 12.0F;
public float jumpSpeed = 8.0F;
public float gravity = 20.0F;
public bool canDoubleJump = false;
private Vector3 moveDirection = Vector3.zero;
private float moveDirectionY = 0;
void Update() {
transform.rotation = Quaternion.Euler (0, Camera.main.transform.eulerAngles.y, 0);
CharacterController controller = GetComponent<CharacterController>();
if (controller.isGrounded) {
canDoubleJump = false;
moveDirection = new Vector3 (Input.GetAxis ("Horizontal"), 0, Input.GetAxis ("Vertical"));
moveDirection = transform.TransformDirection (moveDirection);
if (Input.GetKey (KeyCode.LeftShift)) {
moveDirection *= sprintSpeed;
} else {
moveDirection *= speed;
}
if (Input.GetButtonDown ("Jump") && canDoubleJump == false) {
canDoubleJump = true;
moveDirection.y = jumpSpeed;
}
}
if (Input.GetButtonDown ("Jump") && canDoubleJump && !controller.isGrounded) {
moveDirection.y = jumpSpeed;
Wait();
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
void Wait() {
canDoubleJump = false;
}
}
Comment