Here is my code. I have an empty Gameobject directly underneath the child with a small radius checking the ground every thing seems to be correctly covered, but for some reason the jumping mechanic is very finicky and broken feeling. Can you take a look a tell me what you see? Thank you for your time!
public class PlayerMovement : MonoBehaviour
{
public float speed;
public float height;
public Transform groundCheck;
public float groundCheckRadius;
public LayerMask whatIsGround;
private bool grounded;
private bool doubleJumped;
// Update is called once per frame
void FixedUpdate ()
{
if (grounded)
{
doubleJumped = false;
}
if (Input.GetButton ("Horizontal"))
{
transform.Translate (Vector3.right * speed * Time.deltaTime);
}
if( Input.GetButton("Left"))
{
transform.Translate (Vector3.left * speed * Time.deltaTime);
}
if (Input.GetButton ("Jump") && grounded)
{
//transform.Translate (Vector3.up * height * Time.deltaTime);
Jump();
}
if (Input.GetButtonDown ("Jump") && !doubleJumped && !grounded)
{
Jump();
doubleJumped = true;
}
grounded = Physics2D.OverlapCircle(groundCheck.position,groundCheckRadius,whatIsGround);
}
void Jump()
{
transform.Translate (Vector3.up * height * Time.deltaTime);
return;
}
}