Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 $$anonymous$$ · Jul 03, 2018 at 10:33 PM · 2dfauxgravity

2d Faux gravity

Hello, I am trying to make a game where you can walk around over smll planets, but I can't get the gravity to work, I have foudn some videos online but none of them worked, so I was wondering if anyone could help me. I would like to be able to jump to other planets when you are closer to that planet, but that is just an extra so if that is not possible than that is no problem, the main thing is that I want to be able to walk around on a small planet. Thank you.

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 YBtheS · Jul 04, 2018 at 01:45 AM 0
Share

Is the planet round or flat?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Jul 04, 2018 at 10:01 AM

If you means something like gravitee wars(required flash player) youtube example, that's kinda easy to implement but moderate difficulty to get it the way you want.


Gravity by itself is a quite simple thing and some parts can even be more simplified in a simulated environment. Generally I would recommend to create a single manager script which handles gravity. It's possible to have each object that should be affected by gravity handle it on its own but for performance reasons it's better to handle this at a central place.


The manager would keep a list of "gravity sources" and a list of "affected objects". You may want to add a script to the affected object to communicate the current net gravity vector so the object knows where "down" is at the moment.


Now all you have to do each phyics frame is to iterate through all objects that are affected by gravity. Calculate the distance from an object to each gravity source. This distance vector is used to calculate the gravity this source is applying to our object. In reality the gravity depends on the distance squared. So the closer you get to the source the greater the pull is. So the force you want to apply need to be divided by the magnitude / sqrMagnitude of your distance. Though using the actual formula may not look / feel right at that small scale. You could instead use an AnimationCurve to define the gravity change based on the distance. I mainly refer to the example i've mentioned above.


When you have calculated the force / acceleration vector for each source just add the vectors up to get the resulting net gravity for that object. That means if you have two planets at a certain distance you get a zero gravity point between the two as the gravity of the two planets cancel each other out. Though since the gravity depends on the distance in most cases you get a non-zero gravity vector.


All you have to do is applying that net gravity vector to the object with AddForce. As mentioned above you may store that vector in a variable on a script on each object for later use. This is all you need to get the gravity working.


The controls to move are a different story. In the game i've linked the player actually sticks to the ground and they can't jump. They basically have magnetic shoes so they can even walk on an overhang. So when they stick to the ground they aren't affected by gravity. Though what you actually want is up to you. You have to define what behaviour you want. There is no right or wrong. It depends on the look and feel you want and how well one can play the game. Having physically correct behaviour but the player easily get stuck in edge cases or is trapped in uncontrollable situations is worthless. You should put your main focus on smooth gameplay.


As a final note: Making a game like the one i've linked above is quite hard. It has many different aspects and challanges that need to be solved. Some are easy some are harder. The more experience you have to easier things get. This is the moment your math teacher was talking about all the time. The moment where it's important to actually understand a formula rather than just remembering it.

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

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

176 People are following this question.

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

Related Questions

2D Animation does not start 1 Answer

faux gravity in 2d game 3 Answers

Assets/Scripts/PlayerController.cs(32,49): error CS0126: An object of a type convertible to `float' is required for the return statement 1 Answer

Disable Sprite when keypress (Working Script, just need disble) 0 Answers

Select 2D Object By Mouse ? 4 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