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 Kinfinite · Jun 05, 2021 at 04:17 PM · charactercontrollerslope

How does character controller check slopes?

Does anyone know how the character controller checks slopes? It must somehow because it has a slope limiter that keeps you from walking up something too steep if it's set up that way. I ask because I want a lazy fix to slowing my character if they go up a steep incline, and was thinking something like:

 speed = desiredSpeed - desiredSpeed * controller.slope / 90; 

Obviously the only problem with this is that the controller.slope variable doesn't exist in that form. I'm trying my best to avoid raycasts to check slope if I can find out how the controller checks slope and just take that variable.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by K-e-n · Jun 05, 2021 at 04:54 PM

Look at this link: normal The normal is the up direction of the surface you hit. Normals are always normalized: (0f, 1f, 0f), it is basically scaled down so the highest values is 1. The normal of the top of a table (an average table) would be (0f, 1f, 0f). The normal for the side of a wall (a flat 90 degree wall) would be (1f, 0f, 0f) if the side of the wall was in the positive x direction.

A 45 degree slope would have a normal of (a, 0.5f, b) and (a + b = 0.5f). A normal has a total of 1f. The important thing is that the y is 0.5f. If you multiply this by 90 (to get the angle of the slope): (a, 0.5f * 90f, b) = (a, 45, b). This would be the slope.

 void Update()
 {
       RaycastHit hit;
       hit = Physics.Raycast(transform.position, -transform.up, 0.2f, layer);
       //this next line will work
       float speed = hit.normal.y * 90f;
       //as well as this one
       float speed = hit.normaly.y;
 }

I get the normal of the down raycast. Then, I multiply it by 90f (you do not have to. It is just easier to visualize the angle). A flat surface would have a hit.normal.y of 1f, so a speed of 90f. A 45 degree surface would have a y of 0.5f, so a speed of 45f. The higher the slope, the slower the player.

Important: this was untested, and the second/third paragraph might be slightly wrong. In case it was, at least you know what a normal is, it you can hopefully do what you wanted.

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

136 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

Related Questions

Sliding down a slope with a character controller 1 Answer

mesh collider problem 1 Answer

Prevent character from autojumping when moving down a slope. 0 Answers

CharacterController running downhills 1 Answer

CharacterController Slope Limit not working, character climbs onto everything 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