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
2
Question by kubanvip · Nov 06, 2011 at 04:42 PM · gravityspaceorbit

Natural rotation of orbiting object

Hi

I'm working on a scene, where satellite is orbiting Earth.

Because engine is not emulating point gravity I write my own. It looks like this: At start I set velocity of rigidbody satellite component. Next, in fixed update function, I'm calculating gravity vector, doing some math on it, and applying as a force to the rigidbody.

Looks good but it is not rotating (case 1).

alt text

It should look like case 2. It can't be animation, because satellite must dynamically react to future collisions.

Of course I cannot use rotation in transform component. Another problem is, that angular velocity is not constant (elliptic orbit).

Do you have any ideas how this can be done ? Or maybe I'm not on a right track with my gravity emulation ?

Thanks, Kuba

Comment
Add comment · Show 4
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 syclamoth · Nov 06, 2011 at 05:41 PM 0
Share

To be fair, orbiting satellites will act like picture 1 without outside interference... If you want to fake picture 2, just make it look at the planet, but I don't think you want that.

Basically, picture 1 is more realistic anyway, so it's not your physics model which is at fault, it's your expectations!

avatar image kubanvip · Nov 06, 2011 at 06:28 PM 0
Share

I must disagree: http://www.youtube.com/watch?v=54$$anonymous$$SV2B399o&feature=player_detailpage#t=104s

Think about emulating 2 points, like both ends of this satellite. Rotation is natural.

EDIT: I found wiki article about that: http://en.wikipedia.org/wiki/Synchronous_rotation

avatar image Peter G · Nov 06, 2011 at 08:44 PM 0
Share

It may not be natural, but most satellites need to face the earth. Having a communications satellite point out into space wouldn't do much good except to talk to aliens.

avatar image aldonaletto · Nov 07, 2011 at 12:24 AM 0
Share

If an object enters the gravity field of a planet naturally and without any previous rotation, it may stabilize in a sync orbit - but simulating this by script probably will not give the same result. Physx just emulates real world physics, and many natural phenomena simply are ignored.

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by aldonaletto · Nov 06, 2011 at 08:34 PM

I agree to @syclamoth: I don't think rotation is natural - the satellite just conserves the original angular velocity it had when entered the orbit, unless some asymmetry in its mass distribution make it orient one face to the planet after some time.
You can apply the gravity to the point you want to face the planet, what would simulate a gravity center: use AddForceAtPosition to apply the force at some point. The position is specified in world coordinates, thus you must use TransformPoint to convert the point:

// define the point relative to the satellite center // that should face the Earth: var gravityCenter: Vector3 = Vector3(2, 0, 0);

function FixedUpdate(){ // calculate the gravity force // as before and apply it at the point: var point = transform.TransformPoint(gravityCenter); rigidbody.AddForceAtPosition(gForce, point); } NOTE: Set rigidbody.angularDrag to a higher value (1.5 or above) to kill initial oscillations quickly.

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 Peter G · Nov 06, 2011 at 08:42 PM

Forewarning: This isn't perfectly physically accurate.

I would use a configurable joint. GASP. Yes, configurable joints are quite scary given how many variables there are, but most of the time you won't need more than a few of them. Attach a configurable joint and leave all the variables in their initial states. The code will change the variables that you need.

Now, time for a picture and some simple trig:

http://imageshack.us/photo/my-images/718/satalliteexplanation.png/

That explains the math I'm doing, now here's the code for it:

 using UnityEngine;
 using System.Collections;
 
 public class Satalite : MonoBehaviour {
     
     private ConfigurableJoint joint;
     
     public float rotationalTorque = 1;
     //How strong is the rotational force.
     public Transform orbitingBody;
 
     // Use this for initialization
     void Start () {
         joint = GetComponent<ConfigurableJoint>();
         var rotationDriver = joint.angularYZDrive;
         //tell Unity which rotation mode to use.
         rotationDriver.mode = JointDriveMode.Position;
         //We want to reach a specific rotation, not a velocity.
         rotationDriver.positionSpring = rotationalTorque;
         joint.angularYZDrive = rotationDriver;
         //reassign the joint.
     
     }
     
     // Update is called once per frame
     void Update () {
         var relativePos = transform.position - orbitingBody.position;
         relativePos = relativePos.normalized;
         
         var theta = Mathf.Acos(relativePos.x) * Mathf.Rad2Deg;
         if(relativePos.y < 0)
             theta = 360 - theta;
         
         var rotation = Quaternion.Euler(0 , 0 , 180 - theta);
             //The axis you use will depend on how your object is oriented. You might need to play around with this a little.
         joint.targetRotation = rotation;
         
     }
 }

This causes the object to face towards the center of the planet. If it gets hit, it will sway back and forth trying to realign itself. I have no idea what unit the torque (spring force) is closest to so its tricky figuring out how much to apply.

The only issue I have found with using configurable joints for rotation is that they don't like to have their initial rotation be anything but zeroes. You could fix that by adding in the initial rotation to the final rotation, but I didn't here for simplicity's sake.

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 gundream · Nov 06, 2011 at 06:46 PM

Description

The torque applied to the rigidbody every frame.

// Rotates the object around the world y-axis

constantForce.torque = Vector3.up * 2;

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

6 People are following this question.

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

Related Questions

Is there a Unity Package for this? 1 Answer

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

How can I make an efficient, yet accurate planetary orbit using Apoapsis and Periapsis distance from an object I am orbiting 1 Answer

calculate the future position of an object in orbit 1 Answer

Point gravity implementation lacks precision 2 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