I'm trying to make a 2D platform game where my character makes a ground check before jumping using Physics2D.BoxCast
& some of the platforms have Capsule Collider 2D
& others have Box Collider 2D
. Everything works fine with the Box Collider but when it comes to Capsule Collider, Boxcast is not responding & my character can spam jump on those platforms. Here's my code for ground check,
public bool isGrounded()
{
RaycastHit2D raycastHit = Physics2D.BoxCast(coll.bounds.center, coll.bounds.size, 0f, Vector3.down, castDist, ground);
return raycastHit.collider != null;
}
How can I resolve this issue? Any way to detect both BoxCollider & CapsuleCollider?
I got it, the castDist
variable was causing the issue. It was set to 5
so the detection at bottom was far more than enough, reducing it to 0.1
solved the issue.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.