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 /
This question was closed May 24, 2014 at 06:45 AM by Fattie for the following reason:

Duplicate Question

avatar image
0
Question by mrhussain0334 · Oct 18, 2013 at 03:25 AM · gravitysphere

How to use gravity around sphere?

How can I place a planetary gravity around the sphere such that all objects on sphere such as players and enemies do not fall. They remain attached to the sphere.

Comment
Add comment · Show 3
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 Huacanacha · Oct 18, 2013 at 04:06 AM 1
Share

Without thinking about this too deeply a quick solution would be to turn off the built in Gravitational force (set it to [0,0,0]), then keep a list of all relevant GameObjects and set the constantForce for each object in every FixedUpdate based on the direction from the game object to the center of your planet. If you just need things to stick to the surface, or if all objects will be approximately the same distance from the planet you can use a single gravitational force magnitude for all objects. If you need real planetary gravity just solve the gravitational force equation for each object (F=G*m1*m2/r*r).

avatar image robertbu · Oct 18, 2013 at 04:44 AM 1
Share

Google: "unity3d planet gravity." Lots of hits, lots of info. The questions has been answered many times, plus I believe you will find some tutorials.

avatar image sdgd · Oct 18, 2013 at 10:55 PM 1
Share

my EX script for gravity:

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class PlanetGravity : $$anonymous$$onoBehaviour {
     public float GravityStrength = 10;
     public List<Transform> AddGravityToObject = new List<Transform>();
     public GroundDetection GroundDecScript;
     
     // all that enter Planetary gravitational point are forced to gravity
     void OnTriggerEnter(Collider other){
         if (other.rigidbody != null){
             AddGravityToObject.Add(other.transform);
         }
     }
     void OnTriggerExit(Collider other){
         AddGravityToObject.Remove(other.transform);
     }
     void FixedUpdate (){
         
         // for all objects we are pulling
         for (int i=0; i<AddGravityToObject.Count; i++) {
             // we load ground detection script
             GroundDecScript = AddGravityToObject[i].GetComponent("GroundDetection") as GroundDetection;
             
             // so that force is weaker far site of the planet // weaker force works but not direction don't know why, ...
             // I have to check distance with ray and multiply acordingly to it otherwise it won't work correctly
 //            Temp = transform.position - AddGravityToObject[i].position;
 //            if (Temp.x > 1)    {Temp.x = 160;}        else if ((Temp.x < -1))    {Temp.x = -160;}
 //            if (Temp.y > 1)    {Temp.y = 160;}        else if ((Temp.y < -1))    {Temp.y = -160;}
 //            if (Temp.z > 1)    {Temp.z = 160;}        else if ((Temp.z < -1))    {Temp.z = -160;}
 //            Debug.Log(transform.position - AddGravity[i].transform.position); // distance from planet
 //            if (GroundDecScript != null && ! GroundDecScript.Grounded){
                 AddGravityToObject[i].transform.position = Vector3.$$anonymous$$oveTowards(AddGravityToObject[i].transform.position, transform.position, 0.075f);
                 //rigidbody.AddForce( (transform.position - AddGravityToObject[i].transform.position) * GravityStrength * Time.deltaTime);
 //            }
 //            else if (GroundDecScript == null){
 //                Debug.Log("Does work BUT add the ground detection to object Hiearchy name: " + AddGravityToObject[i].name);
 //                AddGravityToObject[i].rigidbody.AddForce( (transform.position - AddGravityToObject[i].transform.position) * GravityStrength * Time.deltaTime);
 //            }
         }
     }
 }


use what you can :)

OFC if this is what you needed please accept my answer :)

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

16 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

Related Questions

A node in a childnode? 1 Answer

Movement problem? 0 Answers

Double Jump 1 Answer

Sphere rotation in moving direction 1 Answer

How can i make artificial gravity for Kinematic Rigidbody? 3 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