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
3
Question by Orionark · Mar 12, 2012 at 07:56 AM · charactercontrollermoveoncontrollercolliderhitnan

Any reason why OnControllerColliderHit has a NaN normal?

I have a small MonoBehaviour script I attach to a game object in the editor, and the game object also has a CharacterController component attached to it. My question is, in my game, I (rarely) get into a situation where the ControllerColliderHit object passed to my OnControllerColliderHit function has a normal with NaN values. Can anybody think of a reason why this would happen? The rest of my source is pretty lengthy so I won't ask anybody to dig through it, but I use both Move() and transform.position to move the object around.

Here's the small component I use:

 using UnityEngine;
 public delegate void CollisionEventHandler(ControllerColliderHit hit);
 public class CollisionDetector : MonoBehaviour {
   public CollisionEventHandler OnCollision;
   public void OnControllerColliderHit(ControllerColliderHit hit)
   {
     if (float.IsNaN(hit.normal.x))
       Debug.Log("Collision detector NaN normal");
     if (OnCollision != null)
       OnCollision(hit);
   }
 }
Comment
Add comment · Show 3
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 Owen-Reynolds · Mar 12, 2012 at 06:39 PM 0
Share

Try printing hit.gameObject.name (check for gameObject existing first?) $$anonymous$$y guess is that you're "hitting" something that doesn't have a normal (a size 0 collider?)

avatar image Orionark · Mar 12, 2012 at 06:59 PM 0
Share

I only have 2 objects in the scene, a game object with a character controller and a camera attached to it, and then a gigantic plane (1000x1000).

I'm running a client/server simulation here, so could it be that the server is sending a state that positions the controller in an intersecting position with the plane? I did a trace on the collider object and it says it's colliding with 'Plane,' which is my plane, with NaN in all the hit.normal values (x,y,z).

The funny thing is it doesn't actually affect anything. If I just check for a NaN normal in the CollisionDetector object and bail out if it's NaN, the simulation runs along just fine, so it only happens every once in a while. I just run around in circles and eventually it pops up.

The NaN normal also never crops up server-side, just on the client.

avatar image Owen-Reynolds · Mar 13, 2012 at 12:46 AM 0
Share

Ah...so being moved by the network is probably all the odd results.

I'd guess it's not considered a problem, since most people put if(NetworkView.is$$anonymous$$ine) in front of all logic checks, anyway. The idea is that the "real" server-side object will hit and RPC the results to me. The client shouldn't be using laggy data to get inconsitant results.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by aldonaletto · Mar 12, 2012 at 01:35 PM

I have used OnControllerColliderHit a lot, and never observed this issue. Maybe the transform.position changes are fooling the collision system and producing this error - a Character Controller is supposed to be moved only with Move and SimpleMove.
You could try to replace any transform.position assignment like this:

   transform.position = newPosition;

by a Move equivalent:

   character.Move(newPosition-transform.position);

You could also try to do all Move or transform changes in FixedUpdate (the CharacterController belongs to the physics engine like the rigidbodies).

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 Orionark · Mar 12, 2012 at 07:01 PM 0
Share

The NaN normal occurs either way, if I set the position manually or use $$anonymous$$ove. Placing the $$anonymous$$ove in a FixedUpdate isn't an option on account of the choppy movement it produces. I'm not using any of the actual unity physics tools other than the character controller and move. I apply my own forces and keep track of my own velocity, and after all my calculations I just toss my calculated velocity into the $$anonymous$$ove command.

avatar image
0

Answer by Smooth P · Dec 22, 2013 at 06:52 PM

I'm in an extremely similar situation and started getting this in Unity 4.3, leading to hard crashes / lockups. It took me literally days to diagnose, all I knew was that my state data was getting corrupted, and I poured through and logged every piece of physics related floating point math in my codebase, thinking I must have played a bit fast and loose somewhere and forgot that floats aren't reals, or that maybe there was a corner case networking bug, but lo and behold, I find the occasional though incredibly rare NaN filled normal in ControllerColliderHitS.

Why having NaN values in a CC Move would cause a hard crash is beyond me (it should certainly fail more gracefully than that), but a hit normal should quite obviously NEVER NEVER NEVER NEVER NEVER come back NaN. That's simply not valid and breaks the contract of the API.

For now I guess the solution is to assume Unity physics are even more broken than usual and manually guard against NaN normals.

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

7 People are following this question.

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

Related Questions

Enemy with character controller has inconsistent hit detection 1 Answer

Character controller not following moving parent transform properly 3 Answers

CharacterController moves only sometimes 2 Answers

The character controller return null refrence 2 Answers

Control Mid-Air Movement With Character Controller 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