Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by Professor Snake · Dec 15, 2014 at 03:09 PM · collisionvelocitycharacter-controller

Prevent character controller from changing movement direction when colliding with something.

Somewhat of an embarrassing question, but this is something that has been bugging me for a while. Currently, the character controller seems to behave in the following manner when colliding with something (top-down view):

  • Red: Hypothetical wall

  • Blue: Character Controller

  • Yellow: Input Velocity

  • Green: Final Velocity

alt text

How can i make it so that the controller stops moving in this scenario instead of changing velocity? CharacterController.Move() is being used and i would like to avoid anything that would potentially involve SimpleMove.

Comment
Add comment · Show 6
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 taxvi · Dec 15, 2014 at 03:18 PM -1
Share

option one: in your assets folder right click and create new Physics material, set its friction to something high. set the material to additive friction. then select the wall and drop this material on the its collider's physics material slot.

option two: put your walls in the layer called 'walls'. then in your player script add:

 void OnCollisionStay(Collider col){
 
 if(col.gameObject.layer == "walls" && Input.GetAxis("Horizontal") == 0 && Input.GetAxis("Vertical") == 0){
 
 rigidbody.velocity = Vector3.zero;
 
 }
 
 }
avatar image Professor Snake taxvi · Dec 15, 2014 at 08:20 PM 0
Share

Physic material based solution is kind of too much work, unfortunately. There has to be a better workaround. Option two just doesn't work. First of all there's no reason not to use tags ins$$anonymous$$d of layers. $$anonymous$$y character is controlled via a character controller and not a rigidbody. You'd set velocity to vector3 zero when the character collides with the wall and... doesn't want to move?

avatar image taxvi taxvi · Dec 15, 2014 at 08:25 PM 0
Share

wow, you are welcome dude :|

avatar image Professor Snake taxvi · Dec 15, 2014 at 08:35 PM 0
Share

I'm just saying the idea doesn't work. :[

avatar image Kiwasi · Dec 26, 2014 at 12:05 AM 0
Share

Looks like you are going to have to open up the character controller script and rewrite the collision detection script.

avatar image Baste · Jan 13, 2015 at 05:14 PM 0
Share

The default character controller is never going to be exactly what you need, and it's so bloated that it's really hard to rewrite. I'd suggest writing your own.

0 Replies

· Add your reply
  • Sort: 

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

31 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

Related Questions

I want collision boxes to be precise without overlapping each other 1 Answer

Rigidbody2D.velocity out of controll 3 Answers

(Steam VR / Vive) Rigidbody moving in only one direction after collision 1 Answer

How to get collision force, not relative velocity? 1 Answer

Rigidbody Wall Collision Bug/Wall Jitter 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