Hey all,
So I was finally able to get a reliable character controller working with my Unity project.
It all works as intended with the exception of jump. Most of the time, jump works perfectly, but on occasion the button press or release does not register to the engine. I am assuming this has to do with the Button press not occurring during a frame update but I don’t have a good way to prove this.
Can anyone give me some tips?
Here is my current FixedUpdate function. I have tried this in Update as well but get the same issues.
void FixedUpdate () {
Debug.Log ("Fixed Update");
velocity.x = Input.GetAxis ("Horizontal") * 0.15f;
if(Input.GetKey("r"))
{
transform.position = new Vector3 (-5.42f, 3.89f, -0.03f);
velocity.x = 0;
velocity.y = 0;
}
if (controller.isGrounded) {
//Holds player to Ground
velocity.y = -0.001f;
//Debug.Log ("On Ground");
} else {
velocity.y -= gravity * Time.deltaTime;
//Debug.Log ("In Air");
}
if (Input.GetButtonDown ("Jump") && controller.isGrounded) {
velocity.y = .34f;
}
if(Input.GetButtonUp("Jump") && velocity.y > 0) {
velocity.y *= 0.45f;
}
controller.move(new Vector3(velocity.x, velocity.y, 0));
}
Thanks,
Rawhide