Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 DiscGolfer17 · Feb 04, 2013 at 03:55 PM · c#3djoystickorbit

Orbit controlled by virtual joystick

I currently have a planet in my scene located at the origin. I have a space ship placed at (0, 0, -10) which shows my ship in the center of the screen and just outside of the planet.

I am using the Dual Joysticks included in the Standard Assets (Mobile) package for my Android game. I am trying to get the joystick to control the direction the ship moves, so that the ship will orbit the planet continuously in the direction the joystick is pointing. I have tried Transform.RotateAround() by passing in arbitrary values (between -1 and 1) and it works. But I can't seem to get the joystick to control the rotation axis correctly. Any ideas?

If this doesn't make sense, let me know and I will try to explain it differently. Thanks!

Edit:

Here is my current hierarchy:

  • Camera
    • Directional light

  • EmptyGameObject
    • Ship

  • Planet

Here is my code so far that seems to almost work. When I move the joystick a lot the ship seems to rotate around it's local axis on it's own. Also when I attach the camera to move with the ship by putting it under the ship in the hierarchy, the camera keeps flipping and starts restricting movement quite a bit.

 private const float MOVE_SPEED = 50.0f;
 private Vector3 rotationAxis;
 
 if (moveJoystick.IsFingerDown())
 {
     rotationAxis.Set(moveJoystick.position.y, -moveJoystick.position.x, 0.0f);
     transform.RotateAround(Vector3.zero, rotationAxis, MOVE_SPEED*Time.deltaTime);
 }
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
0
Best Answer

Answer by robertbu · Feb 04, 2013 at 08:18 PM

In dealing with this kind of problem, my usual solution is to use an empty game object. Create an empty game object and place it at the center of the planet. Make the ship a child of the empty game object (placed at 0,0,-10) as you have above. Attach your movement script to the empty game object and any rotations will be mirrored by the ship.

Comment
Add comment · Show 4 · 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 DiscGolfer17 · Feb 04, 2013 at 11:44 PM 0
Share

O$$anonymous$$, so that seems to be pretty close. See my edits above for what is happening now, as well as my current code and hierarchy setup. What is the best way to allow the camera to follow the ship freely? Thanks for the help!

avatar image robertbu · Feb 05, 2013 at 05:37 AM 0
Share

I don't know how to answer concerning "camera to follow ship freely" because I have no idea how your game works. For a static position with respect to the ship, you can make the camera a child of the ship. For something more dynamic, there are a number of camera follow scripts around. Take a look at SmoothFollow2. It's out on the Unity Wiki and is billed as, "This is designed to make a camera smoothly follow a ship in space."

avatar image DiscGolfer17 · Feb 05, 2013 at 11:55 AM 0
Share

Sorry, that was bad wording haha... I just need the camera to follow the ship's movement on the same orbit. I tried just making the camera a child of the ship and that works until it gets to about 180 degrees of movement then everything seems to flip and the camera does a quick 180 degree turn until it gets back around and then does it again. Does that makes sense? It seems close, if I can just figure out this small issue. Thanks!

avatar image robertbu · Feb 05, 2013 at 05:14 PM 0
Share

It doesn't make sense for the camera to flip and not the ship. Is the ship flipping rotating and then causing the camera to flip?

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

How to snap a Prefab to the normal of an irregular mesh 1 Answer

Making objects spawn/appear in a triangle formation 1 Answer

How can I add a rotation to my bullets when they are shot? 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