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 super4arn0ld · Jul 04, 2020 at 10:50 AM · transformnot working

I have a transform problem and I really don't know why

I have a sphere with a rigidbody and no gravity. It controls the camera (or it's supposed to) but unity sends me this error message :

;

transform.position assign attempt for 'Sphere' is not valid. Input position is { NaN, NaN, NaN }. UnityEngine.Transform:set_position(Vector3)\ ;

my code has worked before, but for some reason, unity refuses to admit that the sphere has a transform.position...

;

Here is my code:

 // Start is called before the first frame update
 void Start()
 {
 [Range(0.1f, 25f)]
 public float speed;
 [Range(0.1f, 1f)]
 public float sensitivity;
 bool up;
 bool down;
 bool left;
 bool right;
 bool forward;
 bool backward;
 float speedChange;
 float sensChange;
 }

 // Update is called once per frame
 void Update()
 {
     // getting inputs
     up = Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow);
     down = Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow);
     left = Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow);
     right = Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow);
     forward = Input.GetKey(KeyCode.E) || (Input.GetKey(KeyCode.RightShift) && Input.GetKey(KeyCode.UpArrow));
     backward = Input.GetKey(KeyCode.Q) || (Input.GetKey(KeyCode.RightShift) && Input.GetKey(KeyCode.DownArrow));

     speedChange = Input.mouseScrollDelta.y / Mathf.Abs(Input.mouseScrollDelta.y);       // only {-1 ; 0 ; 1}
     if(Input.mouseScrollDelta.y != 0 && Input.GetKey(KeyCode.LeftControl))
     {
         sensChange = Input.mouseScrollDelta.y / Mathf.Abs(Input.mouseScrollDelta.y);
     }
     ;
     // applying inputs /////////////////////////THIS IS WHERE THE ERRORS ARE///////////////
     if (up) transform.position += transform.up * speed * Time.deltaTime; 
     if (down) transform.position += transform.up * speed * -1 * Time.deltaTime;
     if (left) transform.position += transform.right * speed * -1 * Time.deltaTime;
     if (right) transform.position += transform.right * speed * Time.deltaTime;
     ///////////////////////////////////////END OF ERRORS///////////////////////////
     speed += sensitivity * speedChange;
     sensitivity += sensChange * .1f;
 }

Excuse the format, I don't really know how to work with this site yet

Comment
Add comment · Show 1
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 super4arn0ld · Jul 04, 2020 at 03:46 AM 0
Share

A bit that would help:

the errors are on lines 36-39

2 Replies

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

Answer by Namey5 · Jul 04, 2020 at 11:02 AM

At line 29;

 speedChange = Input.mouseScrollDelta.y / Mathf.Abs(Input.mouseScrollDelta.y);

You most likely end up dividing by 0, thus resulting in the NaNs when you try to increment speed. You should perform checks to make sure that the scrollDelta cannot be 0;

 speedChange = Input.mouseScrollDelta.y / Mathf.Abs ((Input.mouseScrollDelta.y == 0f) ? 1f : Input.mouseScrollDelta.y);
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 super4arn0ld · Jul 04, 2020 at 04:41 PM 0
Share

That was the problem. Thanks, I didn't think about dividing by zero.

avatar image
0

Answer by cpmullen · Jul 04, 2020 at 05:41 PM

I am having the same problem. I am new to Unity as far as scripting.... Here is my code...

 public float upf;
 private Rigidbody rig;
 
 void Awake ()
 {
 rig = GetComponent<Rigidbody>();
 }
 
 void Update ()
 {
  Move();
 }
 
 void Move ()
 {
 float xInput = Input.GetAxis("Horizontal") * upf;
 float yInput = Input.GetAxis("Vertical") * upf;
 }
 
 I am also getting an "Skipped updating the transform of this Rigidbody because its comkponents are infinite. Could you have applied infinite forces, acceleration or set huge velocity?" error. PLEASE HELP ME!
 
 
 








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

170 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 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

Transform.Translate causing object to teleport 0 Answers

transform.position not working in OnControllerColliderHit 2 Answers

transform.localscale suddenly stopped working!,transform.localscale not working!!! 1 Answer

transform.position working on Unity editor but not on Android phone? 1 Answer

Area Effect Damage 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