Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by megabrobro · Dec 15, 2017 at 05:01 PM · unity 5rigidbodyvelocityaddforce

Problem reading/getting from rb.velocity value?

Hi everyone, I am trying to give a particular object a boost of force on Y, when its own velocity if over a certain Y velocity.

So imagine a Mario 1 style game, if the mushroom was moving over the block below, and the block below nudged it upwards this will pause it to increase its velocity.y naturally. In my code I'm trying to add a significant boost to it when that happens.

Its very confusing, because I can see by my Debug.Log messages that the velocity is over the set amount, but the boost isnt occuring (NOTE: If i make the set amount for boosting very slow such as 1f or less, then every time it goes over an edge of platform it gets the boost (presumably because it gets a slight bump at the end of the platform). Here is the code, and then the Debug messages, which I think when looked at together describe the problem perfectly.

Can anybody tell me how its possible that the Debug reports the velocity.y to be 5.96... , but the then code that says if (vel.y > 5.9f) // Do this , never gets called?

(NOTE: I already tried putting this part of the code into LateUpdate() and FixedUpdate() but it seemed to have no effect)

             if (rb.velocity.y > 0 )
                 Debug.Log("vel y = " + rb.velocity.y);
             if (rb.velocity.y > 5.5f)
             {
                 Debug.Log("why doesnt it boost!" + rb.velocity.y);
                 if (!beingBoosted)
                 {
                     Debug.Log("BOOSTING NOW = " + rb.velocity.y);
                     rb.AddForce(0f, 0.7f, 0, ForceMode.Impulse); // add small boost to make powerup jump
                     beingBoosted = true;
                 }
             }


the log reads:

vel y = 5.960464E-08 UnityEngine.Debug:Log(Object) PowerupBig:LateUpdate() (at Assets/Scripts/PowerupBig.cs:75)

vel y = 1.266599E-07 UnityEngine.Debug:Log(Object) PowerupBig:LateUpdate() (at Assets/Scripts/PowerupBig.cs:75)

vel y = 5.960464E-08 UnityEngine.Debug:Log(Object) PowerupBig:LateUpdate() (at Assets/Scripts/PowerupBig.cs:75)

vel y = 1.655453 UnityEngine.Debug:Log(Object) PowerupBig:LateUpdate() (at Assets/Scripts/PowerupBig.cs:75)

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

1 Reply

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

Answer by pako · Dec 15, 2017 at 07:59 PM

@megabrobro you are not reading the log right. It doesn't say velocity.y is 5.96, it says velocity.y is 5.960464E-08, which is practically zero! i.e. 5.960464E-08 = 5.960464 x 10^(-08) (read 5.96 times 10 to the power of -8, which is the same as 5.96 divided by 100,000,000 => practically zero). So, this is why vel.y > 5.9f is false.

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 ElijahShadbolt · Dec 15, 2017 at 08:18 PM 0
Share

You can use rb.velocity.y.ToString("0.00") to display the float value to 2 decimal places.

avatar image megabrobro · Dec 15, 2017 at 08:19 PM 0
Share

Ah thank you very much

avatar image Bunny83 · Dec 15, 2017 at 08:52 PM 1
Share

Right, it's crucial to learn Scientific notation.

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

163 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

Related Questions

Rigidbody.Addforce not working in Unity 5.4.1 3 Answers

Can't access rigidbody commands 'Rigidbody' does not contain a definition for... 2 Answers

Setting a delay before dashing. 1 Answer

Why can't I get AddForce or Velocity work? 2 Answers

Problems with velocity in Unity 5 3 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