Question by
EnderGamer67 · Aug 31, 2020 at 10:37 PM ·
collider2dlayeroverlapping
How to check if a collider is overlapping with a layer?
I'm trying to make a VVVVVV copy as my first game, and I need the code to check if one of the two colliders right above and below the player (which I call feet) are overlapping with the ground layer, but I don't know how to make the code do that. This is the code I wrote so far:
using UnityEngine;
public class Movement : MonoBehaviour
{
public bool grounded;
public Rigidbody2D rb;
public GameObject playerFeetU;
public GameObject playerFeetD;
public LayerMask wall;
void Update()
{
if (something i dont know)
{
grounded = true;
}
if (Input.GetKey("up"))
{
if (grounded == true)
{
rb.gravityScale = -rb.gravityScale;
//Flips gravity
}
}
}
}
Thanks!
Comment
Your answer

Follow this Question
Related Questions
How do I find if a 2D collider is overlapping with another 2D collider, rather than just touching? 0 Answers
How to work with Text component on multiple layers (one layer per popup)? 1 Answer
How to avoid overlapping of GameObject without rigidbody? 1 Answer