Search Unity

Trying set angles in a object and rotate

Discussion in 'Scripting' started by vegetamaker, Aug 3, 2020.

  1. vegetamaker

    vegetamaker

    Joined:
    Feb 28, 2017
    Posts:
    37
    Hello! First at all thanks for your help.

    Let me try to explain what is my current problem.
    I did a little script to set in seconds the duration of a day (lets say, for an example, I can manage to sumulate 24 hours in 60 seconds or whatever time I want. But all my trys are with 60 seconds).

    Anyway the next step is sync the rotation of an object (the light) around the scene using that scale:

    Code (CSharp):
    1.         transform.RotateAround(Vector3.zero, Vector3.right, 360 * Time.deltaTime / realSecondsPerDay);      
    2.         transform.LookAt(Vector3.zero);
    If even it works (because it does a 360º rotation in the no-real 24 hours) there is a problem: no matter how I configure the X rotation axis in the Gameobject. It always starts at 90 and I can't find how could I change that.

    And my second problem is, probably, deribed of this one. I will need, time to time, set manually an hour to game (per example player wake up @ 7:00). With my other script and this line, I can set perfectly the angle the light should be, but again failed when trying to rotate from there.

    Code (CSharp):
    1. transform.rotation = Quaternion.Euler(newAngle, 0, 0);
    I am in this point for 2 days already, looking help in Internet non-stop, but no lucky yet.

    Thanks so much and sorry for my English, not main language so trying my best. :3
     
  2. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,605
    Handle your own time tracking in the background. Dont just calculate how many realSecondsPerDay there are, also calculate for each given frame the currentRealSecondsIntoDay. For any given frame you can then easily calculate the percentage of the rotation using current/max. You can also set current in order to set the daytime to, for example, 7:00 by converting between ingame and realtime again.
    Now that you have this, to set any given rotation simply first reset the rotation to default, then rotate to current/max.

    Use Time to keep track of the seconds in the background, set the seconds a day is supposed to take somewhere, then use these two values for everything. Should be easier to keep track of, and you can just write a function to calculate the ingame time based off of these two values.
     
  3. vegetamaker

    vegetamaker

    Joined:
    Feb 28, 2017
    Posts:
    37
    Thanks, ill keep trying :)