Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 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 /
avatar image
0
Question by unity_D45DUkwpGOZm5A · Jan 09, 2019 at 02:23 PM · unity 2drigidbody2dvelocityphysics2daddforce

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

I have a game object ( satellite ) which is it is being attracted by another object(Sun). the satellite rotates (clockwise ) by holding mouse click, and on space key press(Jump), a force pushes the satellite against the gravity. if satellite rotates around the sun whiling jumping, releasing the mouse button causes the satellite to rotate a bit back.

how to fix this?
is there any better way to achieve this gravitational rotation? Tnx in advance.

alt text

 void FixedUpdate()
     {

         if (Input.GetMouseButton(0))
         {
                 transform.RotateAround(center.transform.position, Vector3.back, 50 * Time.deltaTime);
         }

         if (Input.GetKeyDown(KeyCode.Space))
         {
             direction= transform.position - center.transform.position;
             GetComponent<Rigidbody2D>().AddForce(direction* 100 * Time.deltaTime);
         }
             axis = center.transform.position - transform.position;
             GetComponent<Rigidbody2D>().AddForce(axis * 100 * Time.deltaTime, ForceMode2D.Force);         
     }


,

unity-bug.png (15.6 kB)
Comment
Add comment · Show 7
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 Klarzahs · Jan 09, 2019 at 03:39 PM 0
Share

I think the force of the last few frames continue to affect the current frame. So if you release your mouse, the object still has force from before applied to it, which is causing the extra bounce. Try using either Force$$anonymous$$ode2D.Impulse or resetting the Rigidbody.velocity

avatar image unity_D45DUkwpGOZm5A Klarzahs · Jan 09, 2019 at 04:09 PM 0
Share

I checked either setting velocity to 0 or using Force$$anonymous$$ode2d.Impulse on mousebuttonUp , but the problem still remains. maybe I'm doing it in a wrong way

avatar image sean244 · Jan 09, 2019 at 07:45 PM 0
Share

Can you show us how 'axis' is calculated?

avatar image unity_D45DUkwpGOZm5A sean244 · Jan 10, 2019 at 09:29 PM 0
Share

it's calculated is below


axis = center.transform.position - transform.position ;

avatar image sean244 unity_D45DUkwpGOZm5A · Jan 10, 2019 at 09:37 PM 0
Share

So you're constantly setting axis in update?

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by xxmariofer · Jan 15, 2019 at 10:25 AM

Im not sure if your question is how to make the satellite once you stop holding go straightforward to the sun, if thats the case you can set satellite velocity to vector3.zero when Input.GetMouseButtonUp(0) for making sure it doesnt continue previouse speed.

also save the rigidbody in a var in the start since you are accessing in fixedupdate and will cause performace issues.

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

101 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

Related Questions

Need Help with MousePos and dashing 0 Answers

Maintaining the trajectory of a ball when manipulating its velocity in a Breakout/Arkanoid clone 1 Answer

Third frame 'runs' several times 1 Answer

move 2d character affected by physics with velocity and/or add force 2 Answers

Jump problem 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