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 /
  • Help Room /
avatar image
0
Question by cresciviex · Dec 17, 2015 at 04:46 PM · c#2d-platformerrigidbody2dvelocityaddforce

RigidBody2D velocity randomly drops to zero

I'm using a rigibody2D on a cube in Unity. I have a constant force been added to slowly increase the speed and couple of ifs to cap it out if max speed is reached. This works but every now and then before fixed update the velocity randomly goes to zero. In addition at the time when it drops to zero it goes to some random numbers for a couple of frames (for example -5.453111E-16)

 void FixedUpdate()
     {
         float horizontalAxis = Input.GetAxis("Horizontal"); //gets horizontal axis
         Debug.Log("axis: " + Vector2.right * horizontalAxis * speed);
         Debug.Log("velocity.x before addforce: " + rb2d.velocity.x);
         rb2d.AddForce(Vector2.right * horizontalAxis * speed); //adds x force based on input and speed property
         Debug.Log("velocity.x after addforce: " + rb2d.velocity.x);
         //cap out speed to max if more than max (abs)
         if(rb2d.velocity.x > maxSpeed)
         {
             Debug.Log("velocity.x over max: " + rb2d.velocity.x);
             rb2d.velocity = new Vector2(maxSpeed, rb2d.velocity.y);
             Debug.Log("capped velocity.x: " + rb2d.velocity.x);
         }
         if (rb2d.velocity.x < -maxSpeed)
         {
             rb2d.velocity = new Vector2(-maxSpeed, rb2d.velocity.y);
         }
     }

Image of player components:

http://i.imgur.com/Ld542gO.png

Comment
Add comment · Show 2
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 fosmark13 · Apr 20, 2017 at 06:52 PM 0
Share

hi, i now that is an old topic but i have the same problem with my character, it suddenly began to have this behaviour where its rigibody2d drops its y speed to zero without any reason , so the cuestion is... did you solve it?? and how?? i been searching for all the internet without a clear answer

avatar image cresciviex fosmark13 · Sep 12, 2017 at 07:56 AM 0
Share

Since that was long ago I don't really remember if that was the case but I think my floor was tiled and it was stopping on the edges of the tiles.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by hexagonius · Dec 17, 2015 at 11:35 PM

I think it has to do with negating the scale on direction change, which might be bad in your, but is bad in a second case. instead of scaling the transform, put the visual as child object and ROTATE it around y axis. This might solve your problem as well as not break batching.

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 cresciviex · Dec 18, 2015 at 11:29 AM 0
Share

Nope, even if I comment out that part it still drops down to zero. In addition if I release the input and then press it again still doesnt move.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

2D : How to overwrite rigidbody velocity when "skill" input pressed ??? 0 Answers

rigidbody.velocity.x doesn't work :( 2 Answers

Trying to add force to an object... is this done correctly? 0 Answers

AddForce rigidbody 2d not moving object 2 Answers

how to: Velocity or addForce to 2D (Instantiated?) Object 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