Hello, there has been an issue I have been having in my game that has been plaguing me for a while. My character uses a 2D box cast to detect the ground underneath him, however if he jumps through a one-way platform there are a few frames of time where the box cast detects that he is on (or rather in) the ground and if you time it right he will be lodged in the ground. Granted, you aren’t stuck you just have to jump again for it to be right, but its still not ideal for me.
I’ve been doing some research and testing but I cannot for the life of me found the correct way for my player to not get stuck in a one-way platform. I’ve read up on Contact Filters (which I do not understand) and I’ve learned that creating stopgaps like detected the players y velocity won’t be enough for it to be 100% fool proof. If anyone would be kind enough to help me out I’d appreciate it.
public bool isGrounded() //checking ground
{
RaycastHit2D raycastHit = Physics2D.BoxCast(groundCheck.bounds.center, groundCheck.bounds.size, 0f, Vector2.down, groundLayers);
Color rayColor;
if (raycastHit.collider != null)
{
rayColor = Color.green;
}
else
{
rayColor = Color.red;
}
Debug.DrawRay(groundCheck.bounds.center + new Vector3(groundCheck.bounds.extents.x, 0), Vector2.down * (groundCheck.bounds.extents.y), rayColor);
Debug.DrawRay(groundCheck.bounds.center - new Vector3(groundCheck.bounds.extents.x, 0), Vector2.down * (groundCheck.bounds.extents.y), rayColor);
Debug.DrawRay(groundCheck.bounds.center - new Vector3(groundCheck.bounds.extents.x, groundCheck.bounds.extents.y), Vector2.right * (groundCheck.bounds.extents.x), rayColor);
return raycastHit.collider != null;
}
My ground check is a boolean that gets called througout my code, so I don’t exactly know how I can alter it to have more parameters as-is.