Hi,
I am trying to make a 2d character Controller with the code below:
For the most part it works:
The only issue I am having is : when I am jumping and in the Air, if I hit the left arrow or the right arrow it does not respond it keeps moving in the direction before the jump.
So example I am running right and jumped if I hit the left it keeps moving right in the air
Any suggestions ,Thanks
var speed = 8.0;
var jumpSpeed = 15.0;
var gravity = 20.0;
var rotateSpeed = 3.0;
private var grounded : boolean = false;
private var moveDirection = Vector3.zero;
static var hurt:boolean=false;
private var shield : GameObject;
static var freezetime:boolean=false;
var ouchsound : AudioClip;
function FixedUpdate() {
transform.position.z=Mathf.Clamp(transform.position.z, 0, 0);
var controller : CharacterController = GetComponent(CharacterController);
//transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed = speed * Input.GetAxis ("Horizontal");
//controller.SimpleMove(forward * curSpeed);
if (Input.GetKey (KeyCode.RightArrow)){
transform.rotation = Quaternion.Euler(0, 90, 0);
controller.SimpleMove(forward * curSpeed);
}
else if (Input.GetKey (KeyCode.LeftArrow)){
controller.SimpleMove(-forward * curSpeed);
transform.rotation = Quaternion.Euler(0, -90, 0);
}
if (grounded) {
if (Input.GetButton("Jump")) {
moveDirection.y = jumpSpeed;
}
}
moveDirection.y -= gravity * Time.deltaTime;
var flags = controller.Move(moveDirection * Time.deltaTime);
grounded = (flags & CollisionFlags.CollidedBelow) != 0;
//if(controller.collisionFlags == CollisionFlags.Below){
/////////////////////////
}