I made a Character 2d programming, withou character controler, only rigidbody, the problem is that my character have some bugs when jump, sometimes it don’t jump, I think the problem is on the isGrounded.
public class Move2 : MonoBehaviour
{
public bool isGrounded = false;
public float jumpForce = 0;
public float movement = 0;
public void FixedUpdate()
{
if (isGrounded)
{
jumpForce = 0;
movement = 0;
if (Input.GetAxis("Horizontal") > 0)
{
movement = 8;
}
if (Input.GetAxis("Horizontal") < 0)
{
movement = -8;
}
if (Input.GetButtonDown("Jump"))
{
jumpForce = 10;
}
}
else
{
jumpForce -= 0F;
if (jumpForce < 0)
{
jumpForce = 0;
}
}
Vector3 VectorMovement = new Vector3(movement * Time.deltaTime, jumpForce * Time.deltaTime, 0);
transform.Translate(VectorMovement);
}
public void OnCollisionEnter(Collision hit)
{
if (hit.gameObject.tag == "piso")
{
isGrounded = true;
}
}
public void OnCollisionExit(Collision hit)
{
if (hit.gameObject.tag == "piso")
{
isGrounded = false;
}
}
}