• 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 Skjalg · Oct 10, 2011 at 01:07 PM · collisionraycastcharactercontrollernormal

How can i detect the normal of the collider the Character Controller is touching.

This documentation here: http://unity3d.com/support/documentation/ScriptReference/ControllerColliderHit-normal.html claims we can get "The normal of the surface we collided with in world space".

That is NOT the case! The normal we get seems to be the inverted normal of the point we hit on the curvature of the character collider capsule, rather than the surface normal of the object we collided with.

Unity currently is like

Example we walked (left to right) over the peak/edge of a large rotated cube. the Debug.DrawRay function drew those red lines for us. Once the character controller approached the peak the "surface normal" starts bending upwards and than bends downwards again on the other side. That is not what the surface normals of a cube look like. the result it should give us i photoshoped into the right screenshot in green.

What it should look like

If you need further proof /visualization on how the "output"normals change based on which part of the round character collider bottom hits it than have a look at screenshot2.jpg that shows us slowly walking off an edge. Also note how much more narrow the normal angel falloff is compared to the first screenshot further suggesting that this has nothing to do with the surface normals of the standard unity cube primitive

We could see practical application for both kinds of normal output so we are not arguing for removing the current one (that might break many other unity games that depend on it) but we desperately need the "real" functionality that works like the documentation claims it does.

Do you know how I can get the real normal of what I am colliding with without resorting to raycasting every frame? I already have a solution that uses a raycast (basically inverts the normal that I am provided and raycasts in that direction and then gets the correct one).

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

2 Replies

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

Answer by jonas-echterhoff · Oct 10, 2011 at 01:42 PM

Unfortunately, NVidia PhysX does not support getting separate surface normals for both objects in box/capsule collisions. You should get results more close to what you expect when you replace your BoxColliders with MeshCollider. This is not likely to change any time soon, as it is a limitation of PhysX, and probably not a very high priority issue for NVidia to change.

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 DaJuice · Dec 03, 2013 at 06:29 PM

There is a very simple way to achieve this:

Use a Raycast.

 RaycastHit hit;
 if (Physics.Raycast(ray, out hit, rayLength)) { 
     Vector3 normal = hit.normal;
 }

Cast your ray downward from the center of your collider, the normal in a RayCastHit always represents the normal of the surface beign hit.

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

EDIT: This will give you the green normals that you want, but it alone won't help you with the issue of your character slowly falling down an edge, although you could tweak your script based on raycasts so it behaves correctly.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

What's a good way to find the ground normal? 1 Answer

Help Understanding Raycast 2 Answers

[Solved] Character Controller Explosion Detection 1 Answer

Detect RaycastHit on Character Controller 2 Answers

raycast hit point is wrong 2 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