Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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 /
avatar image
2
Question by chrisall76 · Nov 29, 2013 at 12:51 AM · rigidbodycontrollerwallssticking

Rigidbody Sticks to Walls

Hi, I've searched around for a answer but can't find one. Anyway, my rigidbody works fine except when it touches a wall when I jump and I hold forward it sticks the the wall. Anyone able to fix this?

 using UnityEngine;
 using System.Collections;
 
 public class RigidController : MonoBehaviour {
     
     public float walkSpeed = 10;
     public float runSpeed = 20;
     public float jumpForce = 200;
     public float SpeedLimit = 50;
     public bool isGrounded = false;
     public bool inFront = false;
     
     public LayerMask rayMask;
     public float groundedCheckDist = 1;
     public float moveCheckDist = 1;
     
     private float Speed = 10;
 
     void FixedUpdate () {
         inFront = Physics.Raycast (transform.position, transform.forward, moveCheckDist, rayMask);
         isGrounded = Physics.Raycast (transform.position, -transform.up, groundedCheckDist, rayMask);
         Speed = Input.GetButton("Run") ? runSpeed : walkSpeed;
         
         transform.rotation = Quaternion.Euler(Vector3.up * Camera.main.transform.localEulerAngles.y);
 
         rigidbody.velocity = transform.TransformDirection(new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")).normalized) * Speed + Vector3.up * ((Input.GetButtonDown ("Jump") && isGrounded) ? jumpForce : rigidbody.velocity.y);
         rigidbody.velocity = Mathf.Clamp(rigidbody.velocity.magnitude, 0 , SpeedLimit) * rigidbody.velocity.normalized;
     }
 }
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 robertbu · Nov 29, 2013 at 03:03 AM 0
Share

Have you tried setting the physic material and the colliders of both your character and the walls to something other than the default? You can import some sample physic materials:

Assets > Import Package > Physic $$anonymous$$aterials

3 Replies

· Add your reply
  • Sort: 
avatar image
14

Answer by vinfang · Nov 29, 2013 at 05:12 AM

If you look at the potato project that Unity provided for 4.3, you need to create a Physics2D material or Physics3D material, depending on your project. To create one, just right click in Project window of Unity and select Create -> Physics2D Material and then you can modify the material's value such as friction. The value 0 works well but 1 seems to work as well, just toy with the value to see what works well for your char.

Then on the collider objects like your wall, make sure the material is using the new physics material you created, and your char won't get stuck on the walls anymore.

Comment
Add comment · Show 12 · 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 chrisall76 · Nov 29, 2013 at 05:45 AM 0
Share

3D game, checked the project and it doesn't exactly apply the same to what I'm doing. Plus, I don't want to addforce, I want a constant speed that comes to a stop. Not a gradual speed increase

avatar image vinfang · Nov 29, 2013 at 07:35 AM 0
Share

Your method of changing the rigidbody's velocity shouldn't have to change. I'm surprised setting the physics material's friction to 0 didn't help your issue in terms of the character getting stuck to the wall though.

avatar image pokefan491 · May 22, 2014 at 07:56 PM 0
Share

I was having the same problem , thanks so much for fixing this for me your a hero!

avatar image ABerlemont · Jun 11, 2014 at 08:51 AM 0
Share

Yup, using physic material with a friction of 0 fixed it. But I'm now wondering if applying tons of physic material to level geometry will affect performance.

avatar image rocifier · Jun 25, 2014 at 09:16 AM 0
Share

Setting friction to 0 on both solved this. Low values kind of worked too but ended up using 0 on both to avoid some small issues like being able to jump a bit higher whilst against a wall. Cheers.

Show more comments
avatar image
3

Answer by Punfish · Mar 23, 2020 at 03:22 PM

The best solution I've been able to come up with is add multiple colliders on your unit, one which act as the feet and one slightly above the feet and slightly wider. The feet collider will have normal friction while the wider one would have no friction. This ensures you won't stick to walls as the slippery material will always touch the walls first, but also provide you with the proper ground friction to need to not slide everywhere.

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
1

Answer by mj2carlsbad · Mar 21, 2020 at 08:42 PM

On top of the other answer, also make sure your "Friction Combine" isn't set to Maximum or Multiply on either the player's physics material or the wall's physics material

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 NeonTheCoder · Apr 10 at 09:21 AM 0
Share

This helped me figure out for the material on my character controller the friction combine needs to be set to minimum for the normal collider (not feet) so it is truly frictionless, average still adds on some friction from other objects so the collider would stick.

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

27 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

Related Questions

Rigidbody bumping when going down slopes 3 Answers

Stop character from falling/sticking to walls 1 Answer

turn on and off character controller 0 Answers

How can I change my movement scripts so it moves by rigidbodies movement so it doesn't clip 1 Answer

unity auto adding rigidbody to character controller 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