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 TheDDestroyer12 · Sep 02, 2014 at 11:23 PM · physicsplayergravityplanet

Planetary physics for player

I'm working on a planetary shooter where the planets looks something like this:

alt text

I've figured out how to get non-static objects to fall to the ground:

 var planet : GameObject;
 var gravityObject : GameObject;
 var acceleration : float = 2.5;
 var isGrounded : boolean = false;
 
 function Start ()
 {
 }
 
 function Update ()
 {
     
     gravityObject.rigidbody.AddForce((planet.transform.position - gravityObject.transform.position).normalized * acceleration);
 }

But when I apply this to my character (and mobs), I want their bottom to always face the middle of the planet, like in real life, when you for example walk up a hill, you stand straight up relative to the middle of the earth, instead of leaning backwards so that you are standing straight up relative to the ground. Can you explain how I can possibly code that (without pre-made assets)?

I know there is much questions like this, but no one has really answered MY question.

Thanks on beforehand!

unity planetary shooter physics.png (122.2 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
0
Best Answer

Answer by robertbu · Sep 03, 2014 at 04:57 AM

I'm not where you are having trouble with the many other answers to this question. The first task is to get a vector that defines up. From your drawing, you can do it in one of two ways. You can treat the planet as a sphere and use (object.position - planet.position). The second way is to use Collider.Raycast() and use the 'hit.normal' it returns. Assuming the first, a script on the object to be aligned would need to execute the following each frame:

  var up : Vector3 = transform.position - planet.position;
  transform.rotation = Quaternion.FromToRotation(transform.up, up) * transform.rotation;
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 TheDDestroyer12 · Sep 03, 2014 at 02:06 PM 0
Share

Thanks! Couldn't vote up, because I didn't have enough reputation ;)

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

2 People are following this question.

avatar image avatar image

Related Questions

How to simulate moon gravity? 3 Answers

Gravity and rotation control 0 Answers

Planet gravity help need guidance no code 1 Answer

How do i move a player around a planet? (2d) 2 Answers

Multiple Planets with their own gravitational pull 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