Search Unity

Another Rotation Conundrum...

Discussion in 'Scripting' started by Shanefpt80, Sep 26, 2019.

  1. Shanefpt80

    Shanefpt80

    Joined:
    Sep 13, 2019
    Posts:
    2
    Howdy everyone,

    I have been trying to get a custom made spherical skybox to rotate around my game's main terrain plane. I had a script that worked, but it was rotating far too quickly. I tried to dial it down but it nagged me about my decimal value being a float. I hit the drawing boards and cooked up another script using float values with eulerAngles and a Quaternion. It comes back with no errors, and I even tried some of MS VS 2019's optimization tips, which seemingly changed nothing.

    So I have a game object, I want it to rotate on the X axis, steadily, without stopping. I have two objects set as children, both semi-transparent textured spheres with embedded child point lights to be used as a sun and moon. I have reversed the normals on my "AtmoSphere" so my custom graphics are tiled to the inside of the sphere instead of outside. (don't know if any of this matters but figured I would give all possible data I could)

    The goal is one 24 hour cycle per 60 real life minutes. My "AtmoSphere" starts at 0,90,90 and only the 0 should be increasing. However, I noticed that my X axis is going up numerically, but the sky is not revolving, while Y/Z return to 0, and the morning stars graphic of the skysphere is vibrating violently back and forth on the Z axis (or at least that is how the visual appearance looks).

    I am using Unity 2019.2.6f1 64-bit with HDRP...

    Here is my code:

    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class AtmosphereRotation : MonoBehaviour
    7. {
    8.     private const float V = 0.005f;
    9.     public AtmosphereRotation()
    10.     {
    11.     }
    12.  
    13.     public static float V1 => V;
    14.  
    15.     public float RotationDegPerSec { get; set; } = V1;
    16.  
    17.     // Start is called before the first frame update
    18.     void Start()
    19.     {
    20.        
    21.     }
    22.  
    23.     // Update is called once per frame
    24.     void Update()
    25.     {
    26.     float currentAngle = transform.rotation.eulerAngles.x;
    27.     transform.rotation = Quaternion.AngleAxis(currentAngle + (Time.deltaTime * RotationDegPerSec), Vector3.left);
    28. }
    29. }
    30.  
    Was just hoping someone better seasoned than I could take a look at it and tell me what I screwed up...

    Thanks in advance.
     
  2. Shanefpt80

    Shanefpt80

    Joined:
    Sep 13, 2019
    Posts:
    2
    NEVER MIND!!! I'm a total moron... swapped out eulerAngles.x for z and right/left for forward and fixed it... Sorry...