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
0
Question by stanogg · Jul 03, 2015 at 01:56 PM · character controllernormalsangles

Getting slope angle from normals.

Im making a character controller and i want to be able to control the maximum slope angle the character can climp/walk. alt text

Here ^ for example the player wants to walk up a cliff in the direction of arrow 1, but i need this angle (blue):alt text

So i can check if the angle is smaller than 40(or any other value). I also need this to work in all directions. For example 2nd arrow in picture 1. Hope you understand my question. I googled for a bit but i didnt find anything that i could understand. Also im using raycasting for this. Thanks.

pic2.png (76.9 kB)
pic1.png (84.4 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 AlucardJay · Jul 03, 2015 at 03:30 PM 2
Share

http://docs.unity3d.com/ScriptReference/RaycastHit.html

http://docs.unity3d.com/ScriptReference/RaycastHit-normal.html

http://docs.unity3d.com/ScriptReference/Vector3.Angle.html

 angle = Vector3.Angle( hit.normal, Vector3.up );
avatar image stanogg · Jul 05, 2015 at 06:32 AM 0
Share

It works but it always shows the angle in the 2nd pic. I need it to work in all directions, for example if the character would walk down, the angle would be -20, or if the character walked like the 2nd arrow in pic 1. it would return an angle of 14 and so on. I am trying but i just cant figure it out.

3 Replies

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

Answer by Owen-Reynolds · Jul 03, 2015 at 04:57 PM

To get the slope in the direction you want to move, take the angle between the normal, and your "flat" forward. Zero slope will be 90 degrees.

If you have a character controller, or something that never tips, then can just use player.forward -- it will always be flat (have no Y.) Otherwise just use Vector3 pf=player.forward; pf.y=0;. Then just take the angle.

To see how this works, suppose you're walking sideways along a hill (so no slope.) Take one finger as the way you want to move. Take another and tilt it down to be the hill's normal. The 2nd finger is just spinning a little compared to the first, so the angle is still 90. Then redo with finger one for forward into the hill (the xz direction up the hill, but flat, so into the hill.) Compare to that same hill normal, which is now tilted away from your movement finger. Angle more than 90.

You should be able to see the "climb angle" is [angleMath]-90.

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
2

Answer by stanogg · Jul 05, 2015 at 06:56 AM

Just got it working, finally. Im actually only 14 and i dont know much about angles. My equation is: ((Vector3.Angle( hit.normal, transform.forward)) - 90). Thanks everyone for the help! :)

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 wesjmulder · Feb 28 at 10:29 AM

 slopeAngle = Vector3.Angle(slopeHit.normal, Vector3.up);

This should work. If you are using a raycast originating from the center of the player, going down to its feet. To detect slopes. , slopeAngle = Vector3.Angle(slopeHit.normal, Vector3.up); This should work. If you are using a raycast originating from the center of the player, going down to its feet. To detect slopes.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I measure how far from the normal a raycast is when hitting a surface? 0 Answers

Shade Based on Normal Map World Position Angle (Updated) 1 Answer

make one thing flat to another 1 Answer

Rotate Character to match Wall Normals 1 Answer

Getting Player GameObject to rotate to the slope of the ground it is walking on 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