Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 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
4
Question by ROM · Jul 04, 2010 at 07:50 PM · objectrotategravitymoveplanet

Moving object along its own axis

Essentially I've currently got an object which is on a planet (think mario galaxy). If I move the object then it rotates around the centre point of the planet. The problem I have got is in actually moving it. When I move it it moves along the standard axis so it pulls away from the planet like in part 2 of the below image. I want it so it moves along its own axis like part 3 of the below image. Basically i want it so it moves around the planet rather than moving out of it. Does anyone have any idea how to do this?

Heres my current code:

function Update () { var xval : float = -iPhoneInput.acceleration.y; var yval : float = iPhoneInput.acceleration.x + 0.1;

 if(xval > 0.5){
     xval = 0.5;
 }

 if(xval < -0.5){
     xval = -0.5;
 }

 if(yval > 0.5){
     yval = 0.5;
 }

 if(yval < -0.5){
     yval = -0.5;
 }

 var offset : Vector3 = Vector3(xval / 8, yval / 8, 0); 
 rigidbody.MovePosition(rigidbody.position + offset);

}

alt text

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

2 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by spinaljack · Jul 05, 2010 at 12:12 AM

Do this:

function Update(){ transform.position += transform.TransformDirection(Vector3.right)*moveSpeed;

transform.LookAt(spherePosition); }

This makes your character move along its x-axis while always pointing at the middle of the sphere.

http://unity3d.com/support/documentation/ScriptReference/Transform.LookAt.html

http://unity3d.com/support/documentation/ScriptReference/Transform.TransformDirection.html

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 Googster · Jul 06, 2013 at 10:39 PM 0
Share

This was very helpful thank you!

avatar image
1

Answer by Thomas Hentschel Lund · Jul 04, 2010 at 08:47 PM

One way would be to use the classic formula for a position on the point on a circle with a given radius. Right now you are simply calculating the position along one of the axis - you will need to calculate and modify several axis at the same time.

If the center of the planet is at 0,0,0 you can use pythagoras to calculate x,y,z.

I'm unsure if you can do this with manipulating the gravity settings instead, so that your rigidbody calculations do it all for you automagically.

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 ROM · Jul 04, 2010 at 08:55 PM 0
Share

The problem with that might be that pythag would mess up if you put objects on the sphere?

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

1 Person is following this question.

avatar image

Related Questions

walking around a spheroid planet centered at the origin 1 Answer

How do I add gravity to an object? 1 Answer

Rotate Gravity 90 degrees for one object. 1 Answer

How to move an object around with the arrow keys (Javascript) 1 Answer

Move Rigidbody Relative To Camera, quick Q (hopefuly) 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