Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 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 /
This question was closed Feb 07, 2021 at 08:41 PM by Rain478293 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Rain478293 · Feb 07, 2021 at 07:28 PM · unity 2drigidbody2dvelocity

Velocity working really weird

So i'm making basic platformer game in unity2D and i encountered really weird thing in unity 2020.2.2f1. I don't know if it's bug or just weird rules of unity but when object with rigidbody2D and collider2D is not touching anything , everything stays normal. The moment it touches ground, all velocities of falling object start to act like they're about to die. They change from for example -13f to hundreds of billions. I thought that maybe my script that changed velocity on x axis caused it but i made a simple test that looks like this:

 void Update()
 {
     float yVel = rb.velocity.y;
     float xVel = rb.velocity.x;
     print("yVel = " + yVel + " " + "xVel = " + xVel);
 }

And the results are this: alt text

So far so good i haven't got any issues ( visually object stays in one place) related to this but i have huge concerns about future of my project because let's say i would like to change some velocities someday and i honestly don't know what will happen.

Could someone explain to me why is that happening, how can i prevent it or should i just leave it and don't care about that?

tyty.png (25.2 kB)
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

  • Sort: 
avatar image
1
Best Answer

Answer by Eno-Khaon · Feb 07, 2021 at 08:19 PM

You seem to be misunderstanding scientific notation.

In short, you're seeing numbers displayed such as:

 7.450581E-9
 same as...
 7.450581 * 10^-9
 same as...
 7.450581 * 0.000000001
 same as...
 0.000000007450581


The values are so comically small as to practically be zero, while still not being LITERALLY zero.

You won't see anything visibly move at that speed. However, it's important to note that a value that is *close* to zero isn't zero. If you need to watch for when a Rigidbody isn't moving, this is a good place for Mathf.Approximately().

 // effectively: if(sqrMagnitude < Mathf.Epsilon) -- 0.00001f
 if(Mathf.Approximately(rb.velocity.sqrMagnitude, 0f))
 {
     // Not moving
 }
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 Rain478293 · Feb 07, 2021 at 08:37 PM 0
Share

Thanks a lot, sorry for my mistake with scientific notation, value is changing many times per seconds and i lost that "-" somewhere :).

thank you for your time and answer!

avatar image
0

Answer by RodrigoAbreu · Feb 07, 2021 at 08:31 PM

@Rain478293, Just a note - Everything physics based instead of using the Update, use the FixedUpdate. If you use it in Update you might experience some strange behaviours (precision). I'm not sure how you're using it, and also I'm not sure if you put it in the Update just for printing the values.

If those values are not causing any kind of problems in your game, then it's not a problem, they are approximations only.

Comment
Add comment · Show 3 · 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 Rain478293 · Feb 07, 2021 at 08:40 PM 0
Share

Well it's literally chunk of code straight from the script so i didn't changed that. I'm little bit confused because last time some guy told me not to use fixedUpdate when coding movement.

Thanks a lot for the answer, have a nice day :)

avatar image RodrigoAbreu Rain478293 · Feb 07, 2021 at 08:48 PM 0
Share

$$anonymous$$ovement != Physics.

You can achieve movement without using physics.

avatar image RodrigoAbreu Rain478293 · Feb 07, 2021 at 08:55 PM 0
Share

https://docs.unity3d.com/$$anonymous$$anual/ExecutionOrder.html


Good discussion here: https://forum.unity.com/threads/update-vs-fixed-update-vs-late-update.307235/

Follow this Question

Answers Answers and Comments

120 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

Related Questions

Player is not moving 0 Answers

Rigidbody2D.Velocity = Vector2 not changing X Position 1 Answer

,Rotate a gameobject around another while being attracted by its gravity 1 Answer

Rigidbody2D giving incorrect value 1 Answer

Velocity Randomly resets to (0, 0) 0 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