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 SiemLint · Nov 03, 2015 at 12:31 AM · physics3dgravityspherical

How to walk around a 3D sphere?

I'm making a small 3D space simulator. Currently I have a character that I want to have walking around a planet. The problem is that the character acts as if I am rotating him around the planet, while what I am trying to do is using the arrows/WASD to move around and have my own physics functions fix the rest like gravity and keeping the character standing upright. I think the problem lies in my attempt to keep the character upright...

How I do this is using a (invisible) sphere as a base for the player. This sphere has an active collider and a rigidbody. It is oriented with its transform.forward pointing toward the center of the Planet. The "actual" player is a capsule with active collider (no rigidbody) inside this sphere as its child, that has its forward pointing on a 90 degree angle from the sphere (270 on the X-axis in the inspection view). The character script it attached to this capsule.


     myTransform = transform.parent;

     void Update(){
         //gravity doing it's job GravitationalForce() returns a constant for now
         Vector3 gravityDirection = currentPlanet.transform.position - transform.position;
         myTransform.position += gravityDirection.normalized * currentPlanet.GravitationalForce(weight) * Time.deltaTime;


         //rotation kept 90 degrees from gravityDirection
         //invisible sphere around people, pointing downwards topward center of planet
         myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(gravityDirection), 100.0f);

         //movement
         Vector3 movementDirection = new Vector3(0.0f, 0.0f, 0.0f);
         movementDirection += transform.forward * Input.GetAxis("Vertical") + transform.right * Input.GetAxis("Horizontal");
         movementDirection.Normalize();
         myTransform.position += movementDirection * walkingSpeed * Time.deltaTime;
     }

My current hypothesis is that when the outer sphere rotates to lookAt the planet's center it rotates around multiple axes, making the player rotate with it, producing the RotateAround() effect. Could anyone help me get around this problem? Or if my hypothesis is wrong, tell me what the real problem is and help me fix that?

Extra notes: I prefer to make my own physics functions over using Unity's as I'm trying to teach myself game physics. Using Unity's physics ruins this exercise.

Comment
Add comment · Show 1
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 meat5000 ♦ · Nov 03, 2015 at 01:22 AM 0
Share

This is a common question. The answers are on Google.

https://www.google.co.uk/search?q=unity+walk+round+3d+sphere&ie=utf-8&oe=utf-8&gws_rd=cr&ei=_gs4VtvrFsbsUq-1rugG

https://www.google.co.uk/search?q=unity+spherical+gravity&ie=utf-8&oe=utf-8&gws_rd=cr&ei=Ogw4Vv6tBsXqUo6auOgL

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Disabling gravity for a Character Controller 0 Answers

3D cube bounces when dropped from a height. How can I stop that? 1 Answer

Realistic gravity and physics on a playable character. How? 1 Answer

Horizontal gravity physics on 3d game 1 Answer

How can I drag an object with touch on X and Z axis without disrupting the gravity of the rigidbody? 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