Forum begins after the advertisement:
[Part 1] Groundcheck not working
Home › Forums › Video Game Tutorial Series › Creating a Metroidvania in Unity › [Part 1] Groundcheck not working
- This topic has 1 reply, 2 voices, and was last updated 6 hours, 21 minutes ago by
Terence.
Viewing 2 posts - 1 through 2 (of 2 total)
-
AuthorPosts
-
May 28, 2026 at 8:01 pm #19699::
for some reason my charachter always thinks he is on the ground and can jump infinetly, i followed the tutorial exactly but it doesnt work, here is the code:
using UnityEngine; public class PlayerController : MonoBehaviour { [Header("Horizontal Movement Settings")] private Rigidbody2D rb; [SerializeField] private float walkspeed = 1; private float xAxis; [Header("Ground Check Settings")] [SerializeField] private float jumpForce = 45; [SerializeField] private Transform GroundCheckpoint; [SerializeField] private float groundCheckY = 0.2f; [SerializeField] private float groundCheckX = 0.5f; [SerializeField] private LayerMask whatIsGround; // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { rb = GetComponent<Rigidbody2D>(); } // Update is called once per frame void Update() { getinputs(); Move(); Jump(); if (Input.GetButtonDown("Jump")) { rb.linearVelocity = new Vector2(rb.linearVelocity.x, jumpForce); } } void getinputs() { xAxis = Input.GetAxisRaw("Horizontal"); } private void Move() { rb.linearVelocity = new Vector2(walkspeed * xAxis, rb.linearVelocity.y); } bool Grounded() { if (Physics2D.Raycast(GroundCheckpoint.position, Vector2.down, groundCheckY, whatIsGround) || Physics2D.Raycast(GroundCheckpoint.position + new Vector3(groundCheckX, 0, 0), Vector2.down, groundCheckY, whatIsGround) || Physics2D.Raycast(GroundCheckpoint.position + new Vector3(-groundCheckX, 0, 0), Vector2.down, groundCheckY, whatIsGround)) { return true; } else { return false; } } void Jump() { if(Input.GetButtonUp("Jump") && rb.linearVelocityY > 0) { rb.linearVelocity = new Vector2(rb.linearVelocityX, 0); } if(Input.GetButtonDown("Jump") && Grounded()) { rb.linearVelocity = new Vector3(rb.linearVelocity.x, jumpForce); } } }May 31, 2026 at 12:18 pm #19713 -
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)
- You must be logged in to reply to this topic.
Advertisement below: