Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
922 views
in Technique[技术] by (71.8m points)

c# - Boxcast not working with Capsule Collider 2D in Unity

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?

question from:https://stackoverflow.com/questions/65642802/boxcast-not-working-with-capsule-collider-2d-in-unity

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...