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 daviddickball · Jul 01, 2015 at 07:39 AM · javascripterrorrigidbodytransform.positionassign

Getting error transform.position assign attempt for "Player" is not valid on rigidbody

I've seen others ask about this error and some say it appears in the editor only, some say it's because 1 or more of the Vector3 values is null.

I can see in the debug that my project thinks the x and z values are null - but I don't understand why, this is a rigidbody and I don't calculate the Vector3 through my code. I use AddRelativeForce() & AddRelativeTorque()

alt text

This error occurs when my player hits a wall in a specific part of a specific level. Could it be related to the bounce texture I have on my level mesh maybe? Honestly got no idea.

Edit: kmgr wanted to see code so here's the most relevant bit. Like I said, I don't edit the Player's transform directly. Only the rigidbody.

 function FixedUpdate () {
 
     var moveHorizontal : float= Input.GetAxis ("Horizontal");
     var moveVertical : float= Input.GetAxis ("Vertical");
     
         if((moveHorizontal < 0) || Input.GetKey("a"))
         {
             GetComponent.<Rigidbody>().AddRelativeTorque (0,-rotationSpeed,0);
 
         } else if((moveHorizontal > 0) || Input.GetKey("d"))
         {
             GetComponent.<Rigidbody>().AddRelativeTorque (0,rotationSpeed,0);
         } 
         
         if ((moveVertical > 0) || Input.GetKey("w"))
         {
 
             GetComponent.<Rigidbody>().AddRelativeForce (Vector3.forward * speed);
 
         } else if ((moveVertical < 0) || Input.GetKey("s"))
         { 
             
             GetComponent.<Rigidbody>().AddRelativeForce (Vector3.back * speed);
         }
 }

Comment
Add comment · Show 14
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 barbe63 · Jul 01, 2015 at 10:28 AM 1
Share

Actually no, I was wrong anyway since you use AddRelativeForce anyway (sorry I never used that). The Nan stuff https://en.wikipedia.org/wiki/NaN seems to happen most of the time by a division with 0. How do you set the speed and rotationSpeed?

avatar image zach-r-d · Jul 01, 2015 at 11:49 AM 1
Share

Just to help with differential diagnosis, could you confirm whether the problem goes away or doesn't when those four AddRelativeTorque/Force lines are commented out?

avatar image barbe63 · Jul 01, 2015 at 08:33 PM 1
Share

Then I honestly don't know... it's weird. I read somewhere that having a transform.scale to 0 can cause that behaviour too but I guess it's not your case.

avatar image Bunny83 · Jul 01, 2015 at 09:43 PM 1
Share

@barbe63:
NaN has several possible causes, however a division by zero usually results in (+/-)infinity. Only "0 / 0" would result in NaN like you can see in the wikipedia article you mentioned above. It's of course possible that a division by zero that results in infinity might cause a NaN further down the chain of calculations.

Since the mesh compression seem to have fixed it i guess the mesh collider simply has a too cmall triangle (area size -> zero) and during the collision calculations the forces become NaN at some point. $$anonymous$$esh compression will remove unnecessary geometry. So the error is most likely in the mesh / model.

avatar image meat5000 ♦ · Jul 01, 2015 at 09:45 PM 1
Share

Is this a case of Zero-area triangle? That would explain why compression solved it.

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by daviddickball · Jul 01, 2015 at 08:58 PM

I'VE SOLVED IT! I experimented disabling scripts, doing lots of weird things to figure this out. I noticed it always happened when my player collided with a certain place on the level mesh. So I played with mesh import options and changed the Mesh Compression from "off" to "Low"...

And it's now fixed. What an odd bug! Took me a long time to debug this too. Thanks everyone who commented!

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 meat5000 ♦ · Jul 01, 2015 at 09:09 PM 1
Share

Give thanks with thumb up ;)

avatar image
0

Answer by FortisVenaliter · Jul 01, 2015 at 07:10 PM

So, the problem is likely in your speed or rotationSpeed variable. If either of them are NaN (Not a Number), then that will ruin the valid numbers in the rigidbody, causing the bug you are experiencing. If I were you, I'd go through the logic that computes those variables, especially divisions, to make sure they aren't dividing by zero or using imaginary math (X ^ -1, etc).

Short of that, you can simply sanitize your inputs by not calling those AddForce functions if Single.IsNaN() returns true.

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

27 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

Related Questions

Can a object without a rigidbody be triggered by a trigger? 1 Answer

custom rigidbody movement problem 2 Answers

Respawn player from Tornado Twin script issue 1 Answer

onmouseover javascript help 1 Answer

Assets/Standard Assets/Scripts/General Scripts/follow.js(9,59): BCE0044:unexpected char: 0xAD 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