Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
2
Question by GerardMe · Nov 23, 2015 at 12:59 PM · physicsstuckbox collidercapsule colliderledge

Capsule Collider Third Person Controller hanging on a ledge issue.

Hello, I am using a standard third-person-controller from the asset store but if I jump on a ledge of a collider the player is stuck hanging on the ledge. Below is a screenshot to explain my problem.

As you can see the capsule collider collides with the cube and the player-controller thinks it is still airborn

schermafbeelding-2015-11-23-om-130505.png (342.1 kB)
Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image savlon · Nov 23, 2015 at 01:12 PM 0
Share

I haven't looked or used the standard third person character controller, but does but use a Raycast to check for the ground? If so, it may be shooting the Raycast from the centre of the collider and thus missing the platform/ground.

avatar image GerardMe savlon · Nov 23, 2015 at 01:19 PM 0
Share

Yes that happens, but if I change the length of the raycast and it checks grounded as true the problem still occurs

avatar image savlon GerardMe · Nov 23, 2015 at 01:31 PM 0
Share

Regardless of the length, if you're standing on the edge of a ledge and the raycast is shooting from the middle of the collider, it will never touch it as it runs parallel to it. If it's that much of a big deal to you, I would suggest writing your own controller ins$$anonymous$$d of using the standard asset controller. Alternatively, you could hack your way through this issue and add a couple more raycasts from the sides of your capsule collider to check for edges. There is another option, but its use would be deter$$anonymous$$ed by your game. You could just check for an enter collision and set grounded to true based off that. Obviously grounded would equal false when the collision exits. I probably wouldn't go with that approach though, I'd try to implement my own system. It's up to you. Goodluck.

avatar image BIO_K · Jun 08, 2018 at 10:40 AM 0
Share

Did you solve it?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Statement · Nov 23, 2015 at 01:36 PM

If the controller is performing a raycast to test for grounded condition, consider doing a spherecast with the same radius as the collider instead.

I don't know how the controller works, but it could be a solution.

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image savlon · Nov 23, 2015 at 01:51 PM 0
Share

I agree with the spherecast option too. I forgot about that! :)

avatar image GerardMe · Nov 23, 2015 at 09:42 PM 0
Share

I have tried the spherecast method, but I dont really understand on how to use it. Also after adding more raycasts to the bottom of the capsule collider the problem still occurs, Below a screenshot where you can see that one of the raycasts collides with the cube and the character should be grounded.alt text

schermafbeelding-2015-11-23-om-224028.png (198.8 kB)
avatar image Statement · Nov 23, 2015 at 11:07 PM 0
Share

I'll be away for a couple of days most likely. It would be nice if someone want to explain how to use spherecast - otherwise I can get back to OP later.

avatar image GerardMe Statement · Nov 24, 2015 at 09:10 AM 0
Share

Correct me if i'm wrong, but if multiple raycasts won't work, why should a spherecast do work?

avatar image Statement Statement · Nov 24, 2015 at 02:15 PM 0
Share

Quick reply: $$anonymous$$ultiple raycasts may work, but not in all cases. In your specific screenshot, it appear there is an error somewhere. Perhaps the ray starts inside the floor or perhaps your logic of testing each raycast has an error. But even if you fixed that, you would be falling if neither of the raycasts actually hit anything (like standing at the corner of the floor).

avatar image
0

Answer by sxnorthrop · May 18, 2021 at 07:39 PM

My old answer was kinda poo, here's a far better one:

 [SerializeField] private LayerMask m_GroundCheckLayers = 1 << 0;
 [SerializeField, Min(0)] private float m_GroundCheckOffset = 0.1f;

 private CapsuleCollider m_CharacterCollider;

 private void Awake()
 {
     m_CharacterCollider = GetComponent<CapsuleCollider>();
 }
 
 private bool CheckIsGrounded()
 {
     const float skinWidth = 0.01f;
     var center = transform.position + Vector3.up * m_CharacterCollider.radius;
     return Physics.SphereCast(center, m_CharacterCollider.radius - skinWidth, -transform.up, out _, m_GroundCheckOffset + (skinWidth * 2), m_GroundCheckLayers);
 }

This will create a sphere cast that's slightly smaller than your capsule collider (m_CharacterCollider) and shoot it downward kinda like this: https://imgur.com/66FyBQF

The part of the yellow arrow that passes the blue line is the ground check offset, you can use this to increase the distance between the capsule and the ground that would still allow the character to be considered "grounded".

If the "CheckIsGrounded" function returns true, your collider is on the ground.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Capsule Collider switched axises 1 Answer

Multiple Colliders Doing Different Things, Single Object 0 Answers

Box Colliders become disabled randomly at game start 0 Answers

Rigidbody character cannot move once parented to platform 1 Answer

My sphere won't always jump when space is pressed 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges