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 LAZYGAMES_ · Jan 28, 2018 at 08:12 AM · 2dphysicsphysics2dsmoothorbit

Smooth transition for RotateAround

Hi everyone, i am making a 2D game where the player can fly through space. When he gets near a planet he is supposed to get pulled towards the planet and at the same time spin around him.
I solved this by disabling the standart unity gravity and add a Pointeffector2D to the planet. This PointEffector gets activated when the Player enters a Collider placed around the planet. Then a script with the RotateAround function gets activated.

 public class PlanetGravity : MonoBehaviour {
 
     public float speed;
     public Transform target;
     private Vector3 zAxis = new Vector3(0, 0, 1);
 
     void FixedUpdate()
     {
         transform.RotateAround(target.position, zAxis, speed);
     }
     
 } 

That works pretty good but I have the problem that the player instantly starts rotating from the position he is at the moment. Like that the player is performing like a weird corner. alt text

I want the player to get in the orbit smoothly but i have got no idea how to get a smooth transition. I tried to use a delay but then the orbiting starts in some positions to late.
I would be very if someone could come up with an idea or code.

picture2.png (88.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 Hamburgert · Jan 28, 2018 at 08:17 AM

You would need to track the current speed/momentum of the craft. See my answer here, which may give you some ideas:

https://answers.unity.com/answers/1459443/view.html

Comment
Add comment · Show 5 · 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 LAZYGAMES_ · Jan 28, 2018 at 08:34 AM 0
Share

Thanks for your awnser @Hamburgert , but what am I supposed to do with the current speed of the player? The speed in space and while orbiting is the same.

avatar image Hamburgert LAZYGAMES_ · Jan 28, 2018 at 11:45 AM 0
Share

Speed is not just a number of "distance per second". Speed also has a direction in space. Changing direction while maintaining the same "distance per second" is still acceleration, since you are changing speed in the worlds X-direction, Y-direction and Z direction individually.

A spacecraft in orbit is constantly changing its direction while under the influence of gravity. Weightlessness is simply the sensation of being accelerated in perfect synch with your immediate surroundings (spaceship hull, the contained atmosphere, every single part of your body). Speed is always relative to something, and in Unity3d it's usually relative to world space, or local space via parenting.

avatar image Hamburgert LAZYGAMES_ · Jan 28, 2018 at 11:50 AM 0
Share

I just realized that I'm not really helping you use "RotateAround" which is what you're asking. I guess what I'm saying is that RotateAround may not be the best choice for your situation, I$$anonymous$$O.

avatar image LAZYGAMES_ Hamburgert · Jan 28, 2018 at 01:30 PM 0
Share

What am I supposed to use ins$$anonymous$$d? I found no other possibility to get this done. I would be glad if you have a different opportunity to get this working :D

Show more comments

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

195 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Help with 2D physics script 1 Answer

Trying to get a ball to bounce realistically in 2D. 2 Answers

How to rotate a GameObject with another GameObject while simulating gravity? 2 Answers

Limit player speed (2D) 3 Answers

Calculate initial velocity for projectile to reach point at a given angle and calculate angle to reach point at a given velocity. 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