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
3
Question by vectrino · Jun 11, 2012 at 04:59 PM · physicsgravityplanetmoon

How to simulate moon gravity?

Hello! For 7DFPS I'm making a game where you are an astronaut exploring a moon, but I have a problem. I need to have gravity which centers around the moon, which is a sphere. I've looked at a lot of similar questions, but none of them work for me! Just a heads up, I'm using the first person controller. Do any of you know how to achieve?

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 Fattie · Jun 11, 2012 at 07:28 PM 0
Share

each frame, simply add a force pointing towards the middle of the planetoid.

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Youngdeveloper · Jun 11, 2012 at 06:09 PM

In your used "First Person Controller" in Inspector, go to Character Motor(Script) -->Movement and change Max Ground Accelaration to 15, Max Air Acceleration to, lets say 4, also Gravity to 10 and Max Fall Speed to 2. Now you jump and fall slowly, just like on moon.

Comment
Add comment · 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
0

Answer by Youngdeveloper · Jun 11, 2012 at 06:10 PM

Hi, lowering the options like gravity for your fps moving capsule could be the option ( if your using default mesh).

Comment
Add comment · 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
0

Answer by Setzer22 · Jun 11, 2012 at 05:19 PM

Well, acoording Newton's gravitation law, this can be simplified to a force acting on your character, assuming the force vector should always point to the planet's (in your case, the moon's) gravity center, so the sphere center (the moon's gameObject transform.position). So you just have to apply a force on your character, and rotate the force vector so it always looks at the center of the moon.

Also, you cannot work with forces if you aren't on a rigidbody. If you're using the FPS controller, I assume you are using a character controller. This can be easily fixed, as forces are proportional to the acceleration they provoke, so accelerating your character towards the center of the moon should do that same effect. Just some easy physics.

Here's a little bit of pseudo-coding of what I'm talking about:

 define a Vector3 variable called acceleration;
 
 Update function (){
     acceleration = Vector3(0,0,gravity);
     make acceleration look at the center of the moon
     transform.position += acceleration*time.deltaTime
 }

That should do it. Actually, I don't remember if there's a function to make a vector "look" to a given point, but there should be one, if not, you've got the transform.lookAt() method, then you could use that transform's forward vector to give a direction to your acceleration.

EDIT: Check out the Vector3.RotateTowards() method, I don't know if it's what you're looking for, else you'll have to work with a transform instead of a vector3 in order to use transform.lookAt()

Comment
Add comment · Show 3 · 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 vectrino · Jun 11, 2012 at 05:29 PM 0
Share

Thanks! I hope I'm not asking to much, but if you do know how to make this script in either Javascript or C#, could you post that? I'm trying to figure it out on my own but I'm having kind of a hard time and I'm on a tight schedule! Just tried, it isn't working. EDIT: Can't find any documentation on how to use rotatetorwards!

avatar image Setzer22 · Jun 11, 2012 at 05:54 PM 0
Share

Sorry, can't do it atm, I've got my finals tomorrow so I need to study hard :/

avatar image vectrino · Jun 11, 2012 at 06:03 PM 0
Share

It's fine, good luck on finals! :)

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

6 People are following this question.

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

Related Questions

Planet gravity help need guidance no code 1 Answer

Multiple Planets with their own gravitational pull 1 Answer

Adding a force(gravity) to a planet. 0 Answers

Planetary physics for player 1 Answer

Planetary based gravity 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