• 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 /
avatar image
0
Question by lmakor · Mar 07, 2018 at 09:27 PM · physicscharactercharactercontroller

Issue with Character controller and skin width

I just very recently started working with Unity and only today found out about the Character Controller component.

So I immediately wanted to test it and initially liked it very much, however I am experiencing some issues with the skin width.

My issue is that my character has the skin width as an extra layer additional to his radius and height setting, but this alone could be solved by just substracting the skin width from the radius and height.

So the more weird thing is that when I move my char against a wall while just going directly into the direction of the wall it wall have a gap of exactly the amount that the skin width was set to - which I guess makes sense.

However when I move my character not directly into the wall, but while also going up/down (when the wall is e.g. to the left), my character can get closer to the wall.

I will show you an example:

alt text

Here you see that my character(which is the sphere) has an x position of ~-0.8, which makes sense, as the wall starts at -0.9 and the skin width is 0.1. (Also note that for the same reason my character is floating in the air by 0.1 units)

The next picture was taken with the same settings, I just pressed left, left+up, left+down alternating multiple times. Which resulted in:

alt text

Here you see that now my character has an x position of ~-0.897 which means he would be "inside" the wall if he actually had a skin with a width of 0.1

Also note that this picture was made when I was not pressing any buttons anymore, so no more movement was made, this was the permanent position of the character.

So now my issue is that if i make the radius and height of the character controller smaller (by the amount of the skin width), the character will have 0 distance to the wall when moving directly into its direction, but will get "inside it" if the player presses left+up or left+down. Which is just not acceptable.

It generally seems kind of odd that, you can get closer to the wall by pressing left + up/down that by just pressing left.

Can anyone help me and tell my what I should do to fix this issue?

The only thing that comes to my mind is that normally when objects collide, they push themselves away from each other - and so I could implement something that would push away my character from the wall if he gets "inside" it.

Just for the sake of completeness, here is my code:

 public class GameInit : MonoBehaviour
 {
     private float moveSpeed = 1.0f;
     private GameObject cube;
     private CharacterController characterController;
     // Use this for initialization
     void Start()
     {
         //create characcter
         cube = GameObject.CreatePrimitive(PrimitiveType.Sphere);
         cube.name = "brown_cube";
         cube.GetComponent<Renderer>().material.color = new Color(139f / 255, 69f / 255, 19f / 255);
         characterController = cube.AddComponent<CharacterController>();
 
         //set inital position of character
         Vector3 pos = cube.GetComponent<Transform>().position;
         pos.y = 1;
         cube.GetComponent<Transform>().position = pos;
     }
 
     // Update is called once per frame
     void Update()
     {
         Vector3 moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
         characterController.SimpleMove(moveDirection * moveSpeed);
     }
 }

PS: I had the best experience when setting the skin width to 0 or a very small value like 0.001, but the Unity documentation explicitly states that one should not do this.

"It’s good practice to keep your Skin Width at least greater than 0.01 and more than 10% of the Radius."

https://docs.unity3d.com/Manual/class-CharacterController.html

distance-to-groundl.png (349.9 kB)
distance-to-ground-and-wall.png (339.2 kB)
Comment
Add comment · Show 2
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 hexagonius · Mar 07, 2018 at 09:58 PM 0
Share

It's a "Character"Controller for a good Reason. I'm guessing your final character is not a sphere, so with a real Character in place, he usually idles and moves a bit and... is the opposite of collision perfect. Unity is NOT an engine for precision in any case. 2D Phyiscs is approximate, 3D physics is approximate, effects are fake, Sprites are packed with margin because of floatingpoint precision issues... Put your real character in and make him feel right, not collide accurate.

avatar image lmakor hexagonius · Mar 07, 2018 at 10:51 PM 0
Share

Not the answer i was hoping for, but probably the right one.

Just one more question, as you seem to be an experienced person: Do you thing setting the skin width to a quite low value would be really bad? Or do you think i can manually test it and just use the best setting?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by goldheartgames · Feb 27, 2021 at 09:36 PM

Necrobump for this thread, but I'm trying to wrap my head around SkinWidth for the built in character controller and really haven't found any detailed explanations. I've run into this exact example when testing out the character controller and would be interested in understanding the benefits of using skinWidth versus increasing the radius of the collider.

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 SlyZ_ · May 29 at 06:13 PM

Exact same problem for me. Everything is said, please someone give a solution

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

170 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

Related Questions

Voxel engine physics 3rd person character controller 1 Answer

RigidBody Character Controller Bug 0 Answers

character gravity problem 1 Answer

Enable Phyics between CC and RB 0 Answers

Character Controller Pushes Car With Wheel Colliders? 0 Answers


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