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 /
avatar image
1
Question by xthunderduckx · Nov 13, 2019 at 03:07 PM · collisionphysicscharacter controller

How to slow character controller down when colliding with a wall?

I'm looking to replicate newton's second law with the character controller. As of now, the character controller stores a variable called "positionChange," which is a vector3, and every frame the character controller moves by it. This value does not decrease when colliding with walls though, so if the player holds down the movement keys against the wall, then their speed can infinitely increase in the direction of the wall, and additionally, the speed does not decrease, so when moving past the wall, the character controller accelerates to the full speed instantaneously.


How can I make it so that when colliding with walls, the character controller is pushed back in the opposite direction of the wall they are colliding with? alt text Depicted in the above image is the character controller travelling in the direction of the x axis (red arrow). The character controller's "positionChange" vector has a value of 12 on the x axis, and if I were to remove the wall, the character controller would instantly begin moving 12 units per second instead of having to accelerate to 12 like in real life. If the character controller were to be pushed back equally in the direction they are colliding with the wall, then the speed against the wall would be 0, and the player would have to accelerate.


I want to make it so that the player's velocity/speed is pushed back against when they collide with objects, as depicted by the black arrow in the following image:
alt text

charactercontroller.png (21.9 kB)
blackarrow.png (54.5 kB)
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 lgarczyn · Nov 14, 2019 at 03:00 AM 0
Share

Please clarify your question, maybe with a drawing. What do you want to happen, and what is happening?

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by xthunderduckx · Oct 26, 2020 at 04:05 PM

Replicating the law of equal opposite reactions is actually a single line of code. First you need to understand which direction the force is being applied, which is given by the normal of a collision. Secondly, applying the dot product between the current velocity and player velocity produces the amount of force. Multiply this by the normal and you get the amount of force (in the form of a Vector3) to be applied back to the player's current velocity.


It looks like this: playerVelocity -= collision.normal * Vector3.Dot(playerVelocity, collision.normal);, and it runs in onControllerColliderHit().

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 Sspyrshlsx · Jul 10, 2020 at 09:05 AM

For pushing back, have you tried using a bouncy physics material? I don't know if it will work but better give it a try.


Also a possible fix for accelerating on walls is to check if the player's rigidbody has a velocity of 0 on a certain axis. You can check my comment on this post to see what I mean, which hopefully helps.

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 xthunderduckx · Oct 26, 2020 at 04:02 PM 0
Share

I know this is like a year late by this point but I did figure it out. This is a character controller so it does not use physics materials.

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

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

Related Questions

Determinism of collision judgment of Character Controller 0 Answers

How to setup character Collisions? 2 Answers

How to prevent Character Controller from falling through moving Platforms? 4 Answers

CharacterController jumps when colliding with kinematic rigidbodies 1 Answer

Limiting rigidbody physics influence on another rigidbody 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