Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
5
Question by VolTorian · Feb 03, 2020 at 01:36 AM · charactercontrollerjumpingmovecharacter controller

CharacterController glitches if it reaches a ledge while jumping into a wall.

I'm trying to make a script for a Character Controller that allows for movement changes midair and clamps the magnitude of movement when keys of two axes (so a character doesn't move faster in the diagonals). I have modified the script provided in https://docs.unity3d.com/ScriptReference/CharacterController.Move.html and done these things.

However, if I hold forward to keep moving into a wall with a ledge and jump (while still holding forward), the character just glitches when it reaches the ledge. It sort of phases very slightly into the wall and hangs for a moment before dropping back down. The original script in the link above does not behave this way with ledges.

Example gif

The first two jumps are not against the wall.

How would I fix this?

     void Update()
     {
         leftRight = Input.GetAxis("Horizontal");
         forwardBackward = Input.GetAxis("Vertical");
         rotX = Input.GetAxis("Mouse X");
         //rotY = Input.GetAxis("Mouse Y");
         transform.Rotate(Vector3.up, rotX * sensitivity * Time.deltaTime);
 
         if (characterController.isGrounded)
         {
             moveVertical = new Vector3(0, 0, 0);
 
             if (Input.GetButton("Jump"))
             {
                 moveVertical.y = jumpSpeed;
             }
             Debug.Log("Currently grounded.");
         }
         else
         {
             Debug.Log("Currently airborne.");
         }
 
         if (Input.GetButton("Horizontal") && Input.GetButton("Vertical"))
         {
             leftRight = Mathf.Clamp(leftRight, -0.707f, 0.707f);
             forwardBackward = Mathf.Clamp(forwardBackward, -0.707f, 0.707f);
         }
 
         if (forwardBackward != 0)
         {
             characterController.Move(transform.forward * speed * Time.deltaTime * forwardBackward);
         }
         if (leftRight != 0)
         {
             characterController.Move(transform.right * speed * Time.deltaTime * leftRight);
         }
 
         moveVertical.y -= gravity * Time.deltaTime;
         characterController.Move(moveVertical * Time.deltaTime);
         //Debug.Log(moveVertical.y);
     }


Comment
Add comment · Show 1
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 JPhilipp · Feb 03, 2020 at 02:10 PM 1
Share

Is there any particular line or set of lines in your code which, when outcommented, get rid of the glitch you describe on ledges? If so, which ones are they?

5 Replies

· Add your reply
  • Sort: 
avatar image
6

Answer by nickbireli · Aug 22, 2021 at 09:38 PM

Yo! I found out how to fix it! I've been having this problem ever since I made my player object. I didn't like changing the skin thickness cause it didn't look or feel good when playing. The problem is that your player is getting confused if it should climb or what when you jump because your step offset is in effect. What I did was set the step offset to 0.5 (or literally whatever you want), and set it to 0 when you're in mid-air. Then, once you land back on the ground, set it back to your original value. Here's an example:

~~~

 if(isGrounded)
 {
 controller.stepOffset = 0.5f;
 }
 else
 {
 controller.stepOffset = 0f;
 }

Comment
Add comment · Show 2 · 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
2

Answer by NathoSteveo · Dec 05, 2020 at 11:38 PM

Try setting your Step Offset value to something smaller like 0.1. When you jump up near an edge your Step Offset comes into account.

Comment
Add comment · Show 2 · 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 VortexInCortex · Dec 25, 2020 at 09:15 PM 0
Share

Yea you're right it's the step offset that creates the glitch, but then when we reduce it we can't go up stairs :/

avatar image VortexInCortex · Dec 25, 2020 at 10:29 PM 1
Share

found it https://gamedev.stackexchange.com/questions/184512/player-jitters-when-jumping-at-object-edges/187915#187915

avatar image
0

Answer by SpyZzey · Jul 11, 2020 at 12:47 PM

Try playing around with the "Skin Width"-Attribute on your Character Controller.


The Manual (https://docs.unity3d.com/Manual/class-CharacterController.html) says: "Two colliders can penetrate each other as deep as their Skin Width. Larger Skin Widths reduce jitter. Low Skin Width can cause the character to get stuck. A good setting is to make this value 10% of the Radius."


From my personal experience, it seems that those 10% are not enough sometimes.

Comment
Add comment · Show 1 · 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 antisocialite · Aug 31, 2020 at 07:49 PM 1
Share

those 10% are not enough sometimes

sometimes? more like never. this will not work unless you want to make the character controller the size of a tank and completely annihilate any systems you may have that are dependent on the size of it.
avatar image
0

Answer by VortexInCortex · Dec 25, 2020 at 09:11 PM

Same problem here with similar code.

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
avatar image
0

Answer by HairlessGorilla · Apr 17, 2021 at 09:10 AM

Try setting your slope limit to 90 when your character jumps.

For example:

 if (jump)
 {
      characterController.slopeLimit = 90;
 }
 else
 {
      characterController.slopeLimit = 45;
 }
Comment
Add comment · Show 1 · 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 rage_co · Aug 23, 2021 at 12:56 PM 0
Share

i implemented a similar solution, except that it was with step offset(since step offset is what causes the problem), i set it to 0 while jumping and back to the intended value when on ground

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

219 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

How to move a character in one direction only when jumping? 1 Answer

I have a problem in the jump system. 1 Answer

Jump logic issues 0 Answers

Character's jumping mechanism stuck into something invisible 1 Answer

CharacterController.Move with slow animals - they do not move 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