Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Rotate sphere to look at camera based on lat lon

Discussion in 'Scripting' started by unityfearless, Jun 7, 2017.

  1. unityfearless

    unityfearless

    Joined:
    Mar 26, 2013
    Posts:
    19
    Hi All,

    I have a camera at (0,0,0) the sphere (earth) is at (0,0,500). I have feed of lat/lon of points that I need to place on earth/sphere.
    The way I convert from lat/lon to a point on sphere is as follow with (prime meridian crosses the equator is at (0,0,1))
    GameObject latlonPoint = new GameObject();
    latlonPoint.transform.parent = earth;
    latlonPoint.transform.localPosition = Quaternion.AngleAxis(lon, -Vector3.up) * Quaternion.AngleAxis(lat, -Vector3.right) * new Vector3(0, 0, 1);
    This part works great!
    Now I need to rotate the earth so that it always facing the camera cross the current lat/lon I got. I mean the vector connect the earth center point to the current point on its surface based on the lat/lon I got will always facing the camera. Here is what I did
    Create two vectors to rotate earth/sphere so that it is facing fixed camera
    Vector3 fromDirection = latlonPoint.transform.position - earth.position;
    Vector3 toDirection = camera.position - earth.position;
    Then I apply the rotation as
    earth.rotation *= Quaternion.FromToRotation(fromDirection, toDirection);

    This second part seem to work fine for a while and then when it around haft way orbiting the earth, the rotation of the earth seem to go weird and doesn't face the camera as expected. Although the latlonPoint still place correctly based on lat/lon
     
  2. BlackPete

    BlackPete

    Joined:
    Nov 16, 2016
    Posts:
    970
    As I haven't had my morning coffee yet, my brain's still too sleepy to fully figure out the algorithm, but this here sounds like you're running into an angle flipping issue (i.e. -90 becomes 270, etc.).

    If that's the issue, then you just need to normalize the angle so it stays between 0 and 360 degrees (or -180 to 180 or whatever)
     
  3. unityfearless

    unityfearless

    Joined:
    Mar 26, 2013
    Posts:
    19
    Thank you for your response, however it seems to be way above my understanding. Can you elaborate a bit more?
    The angle value between fromDirection and toDirection is pretty small since it keep updating as the earth is rotating and the lat/lon values feed keep updating (live feed that update lat/lon every 1 seconds)
     
  4. BlackPete

    BlackPete

    Joined:
    Nov 16, 2016
    Posts:
    970
    OK I've had my coffee, and carefully re-read your issue. I think the angle flipping issue may have been a red herring. Sorry about that.

    Without a working project handy, I'm going to take a stab in the dark about what a potential issue may be:

    Code (csharp):
    1. earth.rotation *= Quaternion.FromToRotation(fromDirection, toDirection);
    I wonder if this is introducing cumulative floating point error where earth.rotation accuracy may degrade over time. This might fit the description of "the rotation of the earth seem to go weird"?

    If that's the issue, one alternative approach might be:

    Code (csharp):
    1.  
    2. earth.rotation = Quaternion.RotateTowards(earth.rotation, Quaternion.LookRotation(toDirection), someRotationSpeed);
    3.  
    Or just use Quaternion.LookRotation(toDirection) to set it if you don't want to bother with some rotation speed.
     
    Last edited: Jun 8, 2017
  5. unityfearless

    unityfearless

    Joined:
    Mar 26, 2013
    Posts:
    19
    Thank again for your response. However it doesn't work.

    Omitting "fromDirection" vector in the rotation seems doesn't sound right???

    The goal is to rotate the earth/sphere so that the "fromDirection" which is not (x, y, z axis) matching the "toDirection".

    Further test, I see that when the earth rotate weird, I restart the app and play again, it still rotate weird regardless of how many times I restart. Then I found out that the conversion of lat/lon to (x,y,z) using this
    latlonPoint.transform.localPosition = Quaternion.AngleAxis(lon, -Vector3.up) * Quaternion.AngleAxis(lat, -Vector3.right) * new Vector3(0, 0, 1);
    yield two separate series of values as which are away from each other although the render in Unity is correct. This should be the issue.

    Do you have any good/reliable formula to covert lat/lon into (x,y,z)?
    Thank
     
  6. BlackPete

    BlackPete

    Joined:
    Nov 16, 2016
    Posts:
    970
    Alright, I ended up creating a project to test this as I found this to be an intriguing problem. I created a scene that contained just 3 game objects: Camera (sun), and an Earth (helps to have an Earth textured mapped onto it).

    Here's the code I used -- using your algorithm first as a proof of concept:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3.  
    4. public class Earth : MonoBehaviour
    5. {
    6.    public GameObject sun; // use camera for this
    7.  
    8.    public float latitude;
    9.    public float longitude;
    10.  
    11.    public float orbitSpeed = 10f; // angles per second
    12.  
    13.    private float earthOrbit;
    14.    private float earthSunDistance;
    15.  
    16.    private GameObject cartesianDirection = null;
    17.    private float earthRadius = 1f;
    18.  
    19.    private void Awake()
    20.    {
    21.        earthSunDistance = Vector3.Distance(transform.position, sun.transform.position);
    22.        cartesianDirection = new GameObject("Cartesian");
    23.        cartesianDirection.transform.position = Vector3.forward;
    24.        earthRadius = transform.lossyScale.x * 0.5f;
    25.    }
    26.  
    27.    private void Update ()
    28.    {
    29.        transform.localRotation = Quaternion.identity;
    30.  
    31.        // Update earth orbit position
    32.        earthOrbit += Time.deltaTime * orbitSpeed;
    33.        var earthPosition = Quaternion.AngleAxis(earthOrbit, Vector3.up) * Vector3.forward * earthSunDistance;
    34.  
    35.        transform.position = earthPosition;
    36.  
    37.        // Get cartesian location on earth surface of latitude/longitude
    38.        earthRadius = transform.lossyScale.x * 0.5f;
    39.        cartesianDirection.transform.position = Quaternion.AngleAxis(longitude, -transform.up) * Quaternion.AngleAxis(latitude, -transform.right) * transform.forward;
    40.        
    41.        // Rotate earth so cartesian location faces the earth
    42.        var fromDirection = (transform.position + cartesianDirection.transform.position) - earthPosition;
    43.        var toDirection = sun.transform.position - earthPosition;
    44.  
    45.        transform.localRotation *= Quaternion.FromToRotation(fromDirection, toDirection);
    46.  
    47.        // Hack to get camera to always look at the earth as it orbits
    48.        sun.transform.LookAt(transform);
    49.    }
    50.  
    51.    private void OnDrawGizmos()
    52.    {
    53.        if (!cartesianDirection) return;
    54.  
    55.        Gizmos.color = Color.yellow;
    56.        Gizmos.DrawLine(transform.position, sun.transform.position);
    57.  
    58.        var gizmoPos = transform.position + (transform.rotation * cartesianDirection.transform.position * earthRadius);
    59.  
    60.        Gizmos.color = Color.red;
    61.        Gizmos.DrawSphere(gizmoPos, 0.05f);
    62.        Gizmos.DrawRay(transform.position, (gizmoPos - transform.position) * 2f);
    63.    }
    64. }
    65.  
    This script was placed on the Earth game object. The camera was dragged in as the "sun" gameobject.

    When I ran the script, the longitude is actually pretty stable. However, as soon as I introduced some non-zero latitude value, the earth's overall rotation became slightly goofy. Is this the "weird" rotation you're describing?

    If so, I think I see what's happening here:

    The cartesian location (lat/lon) is actually correct. With the earth texture and the sphere gizmo, you can see it remains firmly locked onto a single point on the sphere. So that part looks correct.

    What I think is happening here is Quaternion.FromToRotation has no concept of "up". So it looks like this is a case of the code being technically correct, but is not really producing the desired result.

    Am I describing the issue you're facing correctly?
     
  7. JoshuaMcKenzie

    JoshuaMcKenzie

    Joined:
    Jun 20, 2015
    Posts:
    916
    take your fromDirection and find its inverse.
    Code (CSharp):
    1. Quaternion fromRotation =  Quaternion.Inverse(Quaternion.LookRotation(fromDirection,Vector3.up));
    what this does is it finds the rotation needed to go from the current look rotation (which points to the [lat,lon] point) to Quaternion.Identity. this fromRotation will be the rotation offset you are looking for.

    then take the target look direction and combine it with the inverse rotation.
    Code (CSharp):
    1. Quaternion targetRotation =  Quaternion.LookRotation(toDirection,Vector3.up) * fromRotation;
    multipying two quaternions together adds up their rotations. and unlike normal math, the order you multiply them together matters. So the LookRotation of toDirection is what will point the z-axis of the object (earth) to the target (camera). Then after you multiply in the inverse rotation which looks at the [lat,lon] point, what you get is the offset rotation that you want, your actual target rotation. By using LookRotation you also provide which axis the rotation should consider as up (I wrote them explictly, but if you excluded them the function would assume world up implictly).


    now... simply rotate towards the target rotation
    Code (CSharp):
    1. transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, degreesPerSecond * deltaTime);
    or set it immediately
    Code (CSharp):
    1. transform.rotation = targetRotation;
     
    BlackPete and unityfearless like this.
  8. unityfearless

    unityfearless

    Joined:
    Mar 26, 2013
    Posts:
    19
    Thank you so much for your time. I really appreciated it.
    @BlackPete yes, that is the weird that I mean
    @JoshuaMcKenzie your code work but it also rotate weird.
    I end up adding
    earth.rotation = Quaternion.identity;
    before each new rotation. This will fixed this issue of weird rotation
    I really like your code @JoshuaMcKenzie than mine b/c it stabilize the direction of earth rotation relative to camera more than mine. Mine doesn't have this stabilization.
    Do you know a way to complete stabilize this. I mean I want the the earth rotation appear in the camera like it is rotate from top to bottom of camera always not from other direction?
     
    Last edited: Jun 8, 2017
  9. BlackPete

    BlackPete

    Joined:
    Nov 16, 2016
    Posts:
    970
    Indeed, clearing the rotation on each frame does the trick in keeping the rotation stable.

    Before:
    goofy.gif

    After:
    stable.gif

    Final code:
    Code (csharp):
    1.  
    2. using UnityEngine;
    3.  
    4. public class Earth : MonoBehaviour
    5. {
    6.    public GameObject sun; // use camera for this
    7.  
    8.    public float latitude;
    9.    public float longitude;
    10.  
    11.    public float orbitSpeed = 10f; // angles per second
    12.  
    13.    private float earthOrbit;
    14.    private float earthSunDistance;
    15.  
    16.    private GameObject cartesianDirection = null;
    17.    private float earthRadius = 1f;
    18.  
    19.    private void Awake()
    20.    {
    21.        earthSunDistance = Vector3.Distance(transform.position, sun.transform.position);
    22.        cartesianDirection = new GameObject("Cartesian");
    23.        cartesianDirection.transform.position = Vector3.forward;
    24.        earthRadius = transform.lossyScale.x * 0.5f;
    25.    }
    26.  
    27.    private void Update ()
    28.    {
    29.        transform.rotation = Quaternion.identity;
    30.  
    31.        // Update earth orbit position
    32.        earthOrbit += Time.deltaTime * orbitSpeed;
    33.        var earthPosition = Quaternion.AngleAxis(earthOrbit, Vector3.up) * Vector3.forward * earthSunDistance;
    34.  
    35.        transform.position = earthPosition;
    36.  
    37.        // Get cartesian location on earth surface of latitude/longitude
    38.        earthRadius = transform.lossyScale.x * 0.5f;
    39.        cartesianDirection.transform.position = Quaternion.AngleAxis(longitude, -transform.up) * Quaternion.AngleAxis(latitude, -transform.right) * transform.forward;
    40.        
    41.        // Rotate earth so cartesian location faces the earth
    42.        var fromDirection = (transform.position + cartesianDirection.transform.position) - earthPosition;
    43.        var toDirection = sun.transform.position - earthPosition;
    44.  
    45.        var fromRotation = Quaternion.Inverse(Quaternion.LookRotation(fromDirection, Vector3.up));
    46.        var toRotation = Quaternion.LookRotation(toDirection, Vector3.up) * fromRotation;
    47.  
    48.        transform.rotation = toRotation;
    49.  
    50.        // Hack to get camera to always look at the earth as it orbits
    51.        sun.transform.LookAt(transform);
    52.    }
    53.  
    54.    private void OnDrawGizmos()
    55.    {
    56.        if (!cartesianDirection) return;
    57.  
    58.        Gizmos.color = Color.yellow;
    59.        Gizmos.DrawLine(transform.position, sun.transform.position);
    60.  
    61.        var gizmoPos = transform.position + (transform.rotation * cartesianDirection.transform.position * earthRadius);
    62.  
    63.        Gizmos.color = Color.red;
    64.        Gizmos.DrawSphere(gizmoPos, 0.05f);
    65.        Gizmos.DrawRay(transform.position, (gizmoPos - transform.position) * 2f);
    66.    }
    67. }
    68.  
    69.  
     
    unityfearless likes this.
  10. unityfearless

    unityfearless

    Joined:
    Mar 26, 2013
    Posts:
    19
    Might be this question is not clear?
    I want the the earth rotation appear in the camera like it is rotate from top edge to bottom edge of camera. Right now, it appear is unpredictable. Sometime the earth is rotating from top left corner of camera to bottom right of camera for a while and then it gradually switch to other direction say from bottom center of camera to top center of camera.

    Is there a way to make it so that earth rotation appear in the camera like it is rotate from top edge to bottom edge of camera?
     
  11. BlackPete

    BlackPete

    Joined:
    Nov 16, 2016
    Posts:
    970
    In the code I posted above, if I manually adjust the latitude in real time while the earth is orbiting the camera, it rotates up and down as expected:

    latitude.gif

    Is this what you were trying to accomplish? If not, then I'm not sure I understand what you're trying to do.

    Maybe it'd be better if you created a video to show your issue? That might help us help you :)

    If you don't already have tools handy, here are the tools you can use (they're free):

    Screen recorder: https://icecreamapps.com/Screen-Recorder/
    Animated GIF: http://instagiffer.com/

    EDIT: Actually, maybe you're talking about the earth's orbit? As it it should vertically orbit around the camera instead of horizontally in my sample?
     
  12. unityfearless

    unityfearless

    Joined:
    Mar 26, 2013
    Posts:
    19
    In you case, can you just change lat/lon at the same time in real time and see if the earth are still rotate vertically relative to camera?

    Oh by the way, can you share your project or hierarchy so that I can test your over here if it have the same issue Like I did. Thanks
     
    Last edited: Jun 12, 2017
  13. BlackPete

    BlackPete

    Joined:
    Nov 16, 2016
    Posts:
    970
    Yep, moving both latitude and longitude works as expected. The only minor issue is if latitude goes over 90 degrees, then the earth flips around to the other side -- which is as expected, really.

    Sure, here you go.
     

    Attached Files:

  14. unityfearless

    unityfearless

    Joined:
    Mar 26, 2013
    Posts:
    19
    Thank you for sharing your project.

    Here is what I see in your project:
    1. Earth is orbiting around camera
    2. Camera is also rotating around itself to look at the earth.

    This is different from what I want.
    1. The Camera is fixed in position and rotation
    2. Earth doesn't orbit around the camera but rotating around itself so that based on the real time lat/lon values (of the ISS orbiting projection on earth), the earth will face the fixed camera at that lat/lon value. Or the line connect from camera to earth center has to go through this lat/lon poin on earth.
    3. The earth rotation around itself also need to go in a direction that from camera views, it look like the earth is rotating from top to bottom regardless of the lat/lon values (like the camera is flying over the earth toward the ISS orbiting projection path).
     
  15. BlackPete

    BlackPete

    Joined:
    Nov 16, 2016
    Posts:
    970
    1) You can disable that. It's just for demo purposes.
    2) You can also disable the earth orbiting. It's also just for demo purposes to show that the earth rotation and lat/lon don't interfere with each other. The red sphere represents the lat/lon position on the earth and it's always facing the camera regardless of the earth's orbit.

    3) I'm not sure I see how this is always possible. For example, if you adjust only the longitude, it may look weird to rotate vertically when it's generally a sideway movement. In either case, this means changing the "up" axis you want to rotate around.
     
    unityfearless likes this.
  16. unityfearless

    unityfearless

    Joined:
    Mar 26, 2013
    Posts:
    19
    3) you're right
    Thank you so much @BlackPete for your time. You're awesome!
     
    BlackPete likes this.
  17. JoshuaMcKenzie

    JoshuaMcKenzie

    Joined:
    Jun 20, 2015
    Posts:
    916
    3) simply take the same steps I mentioned before. but instead of using world vector3 up in the look rotations, get the cross product between the from|to Directions
    Code (CSharp):
    1. var OrbitAxis = Vector3.Cross(fromDirection,toDirection);
    and have the Look rotations use that instead.
    Code (CSharp):
    1.  
    2. Quaternion fromRotation =  Quaternion.Inverse(Quaternion.LookRotation(fromDirection,OrbitAxis));
    3. Quaternion targetRotation =  Quaternion.LookRotation(toDirection,OrbitAxis) * fromRotation;
    4.  
    What a Cross Product does is that it takes two lines and finds a third line that would run perpendicular of both lines. essentially this means you can use it to find the axis of rotation. be careful though, if the two reference vectors you pass in are parallel the result would be a zero vector (because its an entire plane that would be perpendicular to both lines, which is infinitely many answers). so if the OrbitAxis is zero you should either cancel the rotation ,snap to target rotation, or fall back to a default rotation (but only if currentRotation != targetRotation otherwise you can get some wobbly rotations at the end).

    FromToRotation should also produce similar rotations and thus similar results. however requires slightly different implementation from what I wrote before.

    you note that this sort of rotation made have the planet appear upsideDown, the may or may not be intended (though it is what should happen in space). of course its also a simple matter to reorient to up as well.

    also if you wanted something really fancy you can use this simple SmoothDamp I wrote for Quaternions a while back so that you can give your rotations a little rotational inertia.
    Code (CSharp):
    1. public static Quaternion SmoothDamp(Quaternion current,Quaternion to, ref Vector3 forwardVelocity, ref Vector3 upVelocity, float smoothTime)
    2.         {
    3.             var forward = Vector3.SmoothDamp(current * Vector3.forward, to * Vector3.forward, ref forwardVelocity, smoothTime);
    4.             var up      = Vector3.SmoothDamp(current * Vector3.up,      to * Vector3.up,      ref upVelocity,      smoothTime);
    5.  
    6.             return Quaternion.LookRotation(forward,up);
    7.         }
    8.         public static Quaternion SmoothDamp(Quaternion current,Quaternion to, ref Vector3 forwardVelocity, ref Vector3 upVelocity, float smoothTime, float maxSpeed)
    9.         {
    10.             var forward = Vector3.SmoothDamp(current * Vector3.forward, to * Vector3.forward, ref forwardVelocity, smoothTime, maxSpeed);
    11.             var up      = Vector3.SmoothDamp(current * Vector3.up,      to * Vector3.up,      ref upVelocity,      smoothTime, maxSpeed);
    12.  
    13.             return Quaternion.LookRotation(forward,up);
    14.         }
    15.         public static Quaternion SmoothDamp(Quaternion current,Quaternion to, ref Vector3 forwardVelocity, ref Vector3 upVelocity, float smoothTime, float maxSpeed, float deltaTime)
    16.         {
    17.             var forward = Vector3.SmoothDamp(current * Vector3.forward, to * Vector3.forward, ref forwardVelocity, smoothTime, maxSpeed, deltaTime);
    18.             var up      = Vector3.SmoothDamp(current * Vector3.up,      to * Vector3.up,      ref upVelocity,      smoothTime, maxSpeed, deltaTime);
    19.  
    20.             return Quaternion.LookRotation(forward,up);
    21.         }
    its not true rotational inertia, but the code is super simple, fast, and in nearly all use cases its more than sufficient.
     
  18. unityfearless

    unityfearless

    Joined:
    Mar 26, 2013
    Posts:
    19
    Thank @JoshuaMcKenzie for your response but I still can't get it works. So what I did is
    // This part is to rotate earth so that it facing fixed camera always => work great!
    earth.rotation = Quaternion.identity;
    Quaternion fromRotation = Quaternion.Inverse(Quaternion.LookRotation(fromDirection, Vector3.up));
    Quaternion targetRotation = Quaternion.LookRotation(toDirection, Vector3.up) * fromRotation;
    earth.rotation = targetRotation;

    // This part is to rotate earth so that it look like it is rotate from top to bottom of camera => doesn't work
    var OrbitAxis = Vector3.Cross(fromDirection,toDirection);

    Quaternion fromRotation = Quaternion.Inverse(Quaternion.LookRotation(fromDirection,OrbitAxis));
    Quaternion targetRotation = Quaternion.LookRotation(toDirection,OrbitAxis) * fromRotation;

    But when I test with this code for the second part, it works great

    // Get the moving direction
    Vector3 dir = latlonPoint.transform.localPosition - previousLatLonPoint.transform.position.transform.localPosition;
    Vector3 cameraUp = cameraTop.localPosition - camera.localPosition;
    // Rotate earth from ISS moving direction to the up vector of cupola
    earth.Rotate(Vector3.forward, Vector3.Angle(dir, cameraUp), Space.World);
     
    Last edited: Jun 14, 2017
  19. unityfearless

    unityfearless

    Joined:
    Mar 26, 2013
    Posts:
    19
    Now I have another question when you're here. I also need to add light/sun into the scene so that it reflects real time base on the current lat/lon of live ISS.
    - Currently the earth is rotating around itself so that it is facing the fixed camera cross a point based on the current live lat/lon feeding from ISS live
    - The earth is also rotating around itself so that it appears in the fixed camera like it is rotating from top to bottom as it is here http://www.isstracker.com/.
    How to position/rotate the sun/light around earth that it reflects real day and night based on current lat/lon and UTC time?
     
  20. JoshuaMcKenzie

    JoshuaMcKenzie

    Joined:
    Jun 20, 2015
    Posts:
    916
    So let me get this straight. Is "rotate" the right term you want to use here? I assume you mean that you want the Planet to appear as if its orbiting the ISS (of course in real life its the opposite, but if the ISS is static it makes sense to have the planet orbit the ISS). if this is the case Rotate is the wrong word for this. The code I posted was with the assumption that the planet was spinning in-place.

    Having the planet orbit the ISS isn't much different.

    Code (CSharp):
    1.  
    2. public class OrbitScript : MonoBehaviour
    3. {
    4.  
    5.     public Transform planet;
    6.  
    7.     //we're gonna piggyback off of the Transform Gizmo to specify which axis to rotate the planet around.
    8.     // similar to directional Lights the position doesn't matter, just its orientation.
    9.     // Its simply to make editing the axis of rotation easy to do in the sceneview
    10.     public Transform planetOrbitAxis;
    11.  
    12.     public float orbitDegreesPerSecond = 1f; //1f means a full orbit in 6 minutes. negative orbits in the opposite direction.
    13.     public float orbitRange = 10f;
    14.  
    15.     private Quaternion currentPlanetOrbit;
    16.  
    17.  
    18.     private void OnEnable()
    19.     {
    20.         orbitRange = (planet.position - transform.position).magnitude;
    21.         currentPlanetOrbit = planetOrbitAxis.rotation;
    22.     }
    23.  
    24.     private void Update()
    25.     {
    26.        
    27.         planetOrbitAxis.Rotate(Vector3.up,orbitDegreesPerSecond * Time.deltaTime,Space.Self);
    28.  
    29.         //position the planet based on the currentPlanetOrbit
    30.         var offset = planetOrbitAxis.rotation * new Vector3(0,0, orbitRange);
    31.         planet.position = transform.position + offset;
    32.     }
    33. }
    34.  
    35.  
    This is a simple orbit script for a perfect circular orbit, it should work fine for something like the ISS. if you want something thats more accurate or realistic then you'll have to jump into astrophysics. You can however read in the ISS's current altitude and feed that into the orbitRange, but it won't give the same illusion (it'll look like the station is going faster as its reaches its Apoapsis, which is incorrect).

    for the Sun. it'll look like it orbits the station as well from the perspective of the station so you can use the same trick. though I wouldn't update it every frame, more like calculate its position when the scene loads. unless you expect people to stare at the scene for days straight, in which case I would use a parameteric function based on a DateTime.now. since such a low orbitDegreesPerSecond * Time.deltaTime would produce such a low number that it would likely lose accuracy due to floating-point precision. heck you might need to do that for the earth as well.

    it all depends on how accurate you need it to be.
     
  21. unityfearless

    unityfearless

    Joined:
    Mar 26, 2013
    Posts:
    19
    Thank @JoshuaMcKenzie for your response. You are right that I used the wrong word. It should be spinning. The earth doesn't translate but spin around itself.
    Thank for the hint of the sun also. "low orbitDegreesPerSecond * Time.deltaTime would produce such a low number that it would likely lose accuracy due to floating-point precision. heck you might need to do that for the earth as well." => correct. I now update based on DateTim.now which yield the correct position of earth and sun although it is not smooth.
     
  22. BlackPete

    BlackPete

    Joined:
    Nov 16, 2016
    Posts:
    970
    I think I'm still confused why the camera needs to be fixed in position and rotation. Wouldn't it be more logical to move the camera (ISS) itself rather than trying to rearrange everything around the camera?
     
  23. unityfearless

    unityfearless

    Joined:
    Mar 26, 2013
    Posts:
    19
    Just imagine that you are on ISS and look back into the earth using a camera.
     
  24. BlackPete

    BlackPete

    Joined:
    Nov 16, 2016
    Posts:
    970
    Yes. And the ISS is orbiting the earth.

    From the camera's point of view, it looks like everything's moving around the camera, but it's actually the camera that's doing the moving. IMO this would make staging the scene so much simpler.

    This really looks like a geocentric vs heliocentric issue to me
     
  25. JoshuaMcKenzie

    JoshuaMcKenzie

    Joined:
    Jun 20, 2015
    Posts:
    916
    I posted this before (but somehow it never went through?)

    If the ISS is a static object (for lightning, physics, occlusion, navigation, etc.) then it makes sense for it to not move. the ISS he has might be in high detail, while the earth is just a sphere with a texture ( and possibly some image effects), the same for the sun, it logical that it'd be cheaper to move them instead... or his ISS might not be fully modeled.

    we don't know all the details with his scene, but from the sound of things the camera position seems like a requirement.

    Yes the world doesn't revolve around the ISS, but from ISS's perspective it does, and the important thing here is selling the illusion of that perspective.
     
  26. BlackPete

    BlackPete

    Joined:
    Nov 16, 2016
    Posts:
    970
    Point taken.

    I'm just thinking about the long term where expanding on this gets increasingly difficult if you wanted to add the rest of the planets and even a star map for increased realism in the background, but yes, it depends on his use case.
     
  27. unityfearless

    unityfearless

    Joined:
    Mar 26, 2013
    Posts:
    19
    @JoshuaMcKenzie and @BlackPete thank you for your inputs and future consideration.
    And yes, JoshuaMcKenzie is right, the requirement is that the actual camera installed in ISS (Cupola) is always look to back to the earth and from the perspective of a person using this camera on ISS, it is static to him and the others (earth, sun, etc) will spin/rotate. Check out this video
     
    BlackPete likes this.
  28. Sir-Gatlin

    Sir-Gatlin

    Joined:
    Jan 18, 2013
    Posts:
    28
    Hey all, This code just about saved my life. One more thing though, Imagine I am not wanting to orbit, and just have the coordinates given always facing the camera, I assumed I could figure it out easily, but having a hard time getting it.
     
  29. Sir-Gatlin

    Sir-Gatlin

    Joined:
    Jan 18, 2013
    Posts:
    28
    found the solution. IF you are wanting the sphere to stay in one place and always show your long lat at the camera all you have to do is set earthPosition to the location you want it to be at.