It was working fine last night but it doesn't work today, the zJumpCount stays at zero after I jump now. If the zJumpcount stays at zero my double jump code doesn't work. I even ctrl+z'd back to the beginning of the session with no luck.
public class zPlayerMovement : MonoBehaviour {
public float zMoveSpeed;
public float zJumpThrust;
public bool IsGrounded;
public float zJumpCount;
private Rigidbody zRB;
void Start () {
zRB = GetComponent<Rigidbody>();
}
void Update () {
if (IsGrounded == true)
zJumpCount = 0f;
if (Input.GetKey(KeyCode.A))
zRB.transform.Translate(Vector3.left * zMoveSpeed);
if (Input.GetKey(KeyCode.D))
zRB.transform.Translate(Vector3.right * zMoveSpeed);
if(Input.GetButtonDown("Jump") && IsGrounded == true)
{
zRB.AddForce(Vector3.up * zJumpThrust, ForceMode.VelocityChange);
zJumpCount++;
}
if (IsGrounded == false && zJumpCount > 0 && zJumpCount < 2)
{
if (Input.GetButtonDown("Jump"))
{
zRB.AddForce(Vector3.up * zJumpThrust, ForceMode.VelocityChange);
zJumpCount++;
}
if (IsGrounded == false && zJumpCount >= 2)
{
if (Input.GetButtonDown("Jump"))
return;
}
}
}
void OnCollisionStay (Collision collisionInfo)
{
IsGrounded = true;
}
void OnCollisionExit (Collision collisionInfo)
{
IsGrounded = false;
}
}
zJumpCountafloatinstead of anint? (This could create issues with your comparisons because of floating point errors.) \$\endgroup\$