Hi guys
I’m brand new to game development and I’m in desperate need of some help please.
So my player can jump but each time my player drops down from the ledge and lands on the sprite that has a 2d box collider my player isn’t able to jump anymore.
Code:
public class PlayerMovement2 : MonoBehaviour
{
private float horizontal;
private float speed = 8f;
private float jumpingPower = 16f;
private bool isFaceingRight = false;
[SerializeField] private float maxSpeed;
[SerializeField] private Rigidbody2D rb;
[SerializeField] private Transform groundCheck;
[SerializeField] private LayerMask groundlayer;
void Update()
{
horizontal = Input.GetAxisRaw(“Horizontal”);
if (Input.GetButtonDown(“Jump”) && isGrounded())
{
rb.velocity = new Vector2(rb.velocity.x, jumpingPower);
}
if (Input.GetButtonUp(“Jump”))
{
rb.velocity = new Vector2(rb.velocity.x, rb.velocity.y * 0.5f);
}
Flip();
}
private void FixedUpdate()
{
rb.velocity = new Vector2(horizontal * speed, rb.velocity.y);
}
private bool isGrounded()
{
return Physics2D.OverlapCircle(groundCheck.position, 0.2f, groundlayer);
}
private void Flip()
{
if (isFaceingRight && horizontal < 0f || !isFaceingRight && horizontal > 0f)
{
isFaceingRight = !isFaceingRight;
Vector3 localScale = transform.localScale;
localScale.x *= -1f;
transform.localScale = localScale;
}
}
private void LateUpdate()
{
Debug.Log(rb.velocity.magnitude);
if (rb.velocity.magnitude > maxSpeed)
{
rb.velocity = (Vector2)Vector3.ClampMagnitude((Vector3)rb.velocity, maxSpeed);
}
}
}