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
1
Question by James · Mar 22, 2010 at 10:14 PM · physicsgravity

How do I make a small planet with gravitational pull?

I have a rocket ship flying into space in a 2D (3D art) side-scrolling game. My question is, assuming the gravity within the project settings is necessary to the gameplay, how do I create isolated gravitational fields with limited range?

For example, if I'm flying my rocket against the gravity pulling down, I also want to encounter planetoids that pull me in if I get too close. It must be created within the physics system because the rocket needs to be able to resist it (or even land on the planetoid).

Thank you for any answers sent my way!

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

4 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by James · Mar 23, 2010 at 07:46 PM

Thanks for the help everybody, here's how I ended up solving the problem.

function Update () {

}

function OnTriggerStay (other : Collider) { other.attachedRigidbody.useGravity = false;

 var direction = -(other.attachedRigidbody.transform.position - transform.position);

 if (other.attachedRigidbody)
 {
     other.attachedRigidbody.constantForce.force = direction;
 }

}

function OnTriggerExit (other : Collider) { other.attachedRigidbody.useGravity = true; other.attachedRigidbody.constantForce.force = Vector3.zero; }

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
7

Answer by DigitalDogfight · Mar 23, 2010 at 05:34 AM

I saw your post and think this is worth taking a look at on the Unify Wiki page. It has a Simulation section on the scripts page.

Quote from page: "Gravity.js- Provides a relatively accurate simulation of body-to-body gravity (i.e. plantary gravity)."

Here is the link: http://www.unifycommunity.com/wiki/index.php?title=Gravity

I'm new too, hope it helps.

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
1

Answer by n8 · Mar 22, 2010 at 10:19 PM

I am no expert by any means, but my first thought would be to have a sphere with sphere collider that would represent the reach of the gravitational pull. set the collider to be a trigger. Then you would need a script on the object that is going to be acted upon by the gravity that would register that it is in range to be under the gravitational pull and then calculate the distance from the planet to work out how much gravity should be applied. This is where I would start, but that doesn't necessarily mean that it would be the best way.

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 user-1794 · Mar 23, 2010 at 03:34 AM

To add to that, the way I would apply the gravity in the script would probably be to alter the rotation and transforms, so every second the ship should be moved some amount closer, or something along those lines.

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 KvanteTore · Mar 23, 2010 at 10:50 AM 0
Share

but that kind of works against the physics engine in unity. Adding forces to the rigidbody component is usually a better idea

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

No one has followed this question yet.

Related Questions

How do i stop rigid bodies jumping? 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

hit.rigidbody.useGravity problem? 1 Answer

How to make an axis always face an object? 2 Answers

Changing gravity affecting 'random movement' behaviour script - my NPCs go crazy, what should I do? 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