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
0
Question by FineBrisk · Mar 15, 2020 at 08:52 AM · forcerigidbody.addforcerigidbody.velocityrigidbody-collisionrigidbody physics

Rigidbody physics; forces doesnt move gameobject in a desired way

i have sphere with rigidbody component bordered by two cubes up and down the sphere that are fattened on x axis to seem like a wall. Now i am trying to make it move gradually increasing the velocity over time to the right (x axis)and the only inputs it takes is mousebutton press and when it happens it moves up or down (in opposite direction before input click) and when it touches the boundary walls it should again start to move at the same speed as before. the goal is to make it .smooth natural with including up and down movements when input is recieved. in order to achieve this i unchecked gravity so that it stays up or down and added a constant force in x axis. now whenever the input cilick happens this code runs rigidbody.AddForce(0,*speed*p,0 ,ForceMode.Impulse)here p is 1 or -1 it flips the previous direction but after moving up or down it slows down and then again paces back which breaks the flow. I have tried several different ways. i tried to store the velocity just before the click and then add it with addforce (this stored velocity vector and impulse forcemode). i alsoft tried removing constant force component and move it at a constant speed in fixedupdate and various other methods, please take a look at the snaps of all the different codes that are attached with this question. None of them produce desired natural flow, they all slow down the ball after collision but only adds up the velocity gradually even when using add force with impulse. now i know there is a possibility to not use forces at all but i really want to know if this could be done with forces. PLEASE HELP!!! image of the setup alt text

hh.png (15.9 kB)
aaa.png (37.8 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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Link17x · Mar 15, 2020 at 09:42 AM

You are calling a method every frame, which starts a coroutine every frame. Firstly, you should use FixedUpdate for physics rather than Update. Secondly, you don't want to be calling a coroutine in any kind of Update loop, because when you start a coroutine it will be repeating itself every 0.2 seconds. Every time you start a coroutine, it will start a new one rather than overwrite the current one.


Change this so you either use FixedUpdate or only one coroutine and you can use WaitForFixedSeconds. Then call your coroutine in Start or where ever (but make sure it isn't in an Update loop)


See how your physics behaves after that, then go from there.

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 FineBrisk · Mar 16, 2020 at 07:22 AM 0
Share

Thank you for replying. i totally missed that perhaps because i was too tired by the time i came to this particular idea to try and improve for the desired outcome as i thought it might never produce effect with forces and planned to try translate or moveposition or other. although i will try this again and revert back on the progress if any. Thanks :)

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

126 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

Related Questions

Do rigid bodies with force add force to other objects? 0 Answers

How to limit only the Rigidbody.velocity from player input? 1 Answer

How to make RigidBody's movement using fixed movement/velocity and other forces all together? 3 Answers

How would you code a Wind script? 1 Answer

Rigidbody velocity updates on wrong collision Object,[2D] Rigidbody velocity updates on wrong collision object, 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