beginner here just trying to learn the basics. I was following this tutorial but I ran into some trouble. Heres a screenshot of unity
So the tutorial calls for tagging the terrain with "Grounded" and essentially checks if the 2D collision box for GroundCheck collides with anything with a "Grounded" tag using the Move2D and Grounded scripts below. Note that the Move2D script is a component of the Player gameobject.
Move2D
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Move2D : MonoBehaviour
{
public float movespeed = 5f;
public float jumpforce = 10f;
public bool isGrounded = false;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
Jump();
Vector3 movement = new Vector3(Input.GetAxis("Horizontal"),0f, 0f);
transform.position += movement * Time.deltaTime * movespeed;
}
void Jump(){
if (Input.GetButtonDown("Jump") && isGrounded == true){
gameObject.GetComponent<Rigidbody2D>().AddForce(new Vector2(0f, 5f), ForceMode2D.Impulse);
}
}
}
Grounded.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Grounded : MonoBehaviour
{
public GameObject Player;
// Start is called before the first frame update
void Start()
{
Player = gameObject.transform.parent.gameObject;
}
// Update is called once per frame
void Update()
{
}
private void OnCollisionEnter2D(Collision2D collision)
{
if(collision.collider.tag == "Ground")
{
Player.GetComponent<Move2D>().isGrounded = true;
Debug.Log("test");
print("GROUNDED");
}
}
private void OnCollisionExit2D(Collision2D collision)
{
if(collision.collider.tag == "Ground")
{
Player.GetComponent<Move2D>().isGrounded = false;
}
}
}
The error I'm running into is that it appears unity isn't recognizing that the player has collided with the tilemap collision box, so the bool isGrounded is just perpetually false and the player is unable to jump. Any help would be appreciated!
EDIT: below are screenshots of configs of Grid, gound, and GroundCheck in that order