Hello, this will hopefully be a quick one.
I just want to make a raycast that detects the layers that could potentially be ceilings so that the player won’t stand up if it is touching them (so that they won’t get stuck obviously). I have a boxcast that is being used in the same script but that is using another collider, so I don’t think that is the problem. I’m always reluctant to use raycasting and this is why because I have no clue what my issue is. Any help would be greatly appreciated!
private bool hittingCeiling()
{
RaycastHit2D hit = Physics2D.Raycast(stand.bounds.center, Vector2.up, ceilingCheckDistance, ceilingLayer);
Color rayColor;
if (hit.collider != null)
{
Debug.Log("hitting ceiling");
rayColor = Color.green;
}
else
{
rayColor = Color.red;
}
Debug.DrawRay(stand.bounds.center, Vector2.up * ceilingCheckDistance);
return hit.collider != null;
}
It’s pretty short but unity is acting like I’m not even calling a raycast so I’m big confused.