Search Unity

2d in a All-around 360 degree motion? Billboard sprite?

Discussion in 'Scripting' started by Ninekorn, Mar 8, 2017.

  1. Ninekorn

    Ninekorn

    Joined:
    Aug 12, 2016
    Posts:
    66
    Hello Unity community. I have been quite annoying in the recent few days to ask so many questions in here but I got another one coming in. Sorry in advance. So it's quite simple to explain but not that simple to code... I am using a 3d mesh from the unity asset store. The 3d mesh is textured. I am using Sprite Maker to make 2d Sprites from that 3d mesh. I am trying to make a full 360 or 720 motion capture (or whatever it is called) to have a complete motion capture by 45 degree incréments of all sides of the skull... The thing is it is SOOO tedious to write a code with Euler Angles Or relative points with Inverse Transform Point to make the skull rotate on each 45 degree Incréments that I am about to smash my head on the walls. Im serious it is very long to code in and to test unless there is an easier way. So My goal will be to use this asset in a game that kinda looks like the old Doom series in 2d. So if anyone got any idea and wants to share im all ears (eyes). Here is a video that I put online to show a 360 motion on the Y Axis and a 360 motion on the X Axis. Now I've still got to implement a 360 motion on each 45 degree Incréments of the Y Axis then X Axis then Z Axis... Wow it's tedious.

     
  2. Laperen

    Laperen

    Joined:
    Feb 1, 2016
    Posts:
    1,065
    what's the purpose of converting 3d assets to 2d if they are going to be used in a 3d environment anyway?
     
  3. Ninekorn

    Ninekorn

    Joined:
    Aug 12, 2016
    Posts:
    66
    Well the Old Doom game did this and it didn't hurt anyone did it? nah Im kidding.Thanks for answering. Actually it might be isometric view or 3d view I am not sure yet. I just want to do something different. Plus with 2d asset I will have less lag if I port the game to mobile. Sprites have much less triangles then 3d Mesh.
     
  4. Laperen

    Laperen

    Joined:
    Feb 1, 2016
    Posts:
    1,065
    The mobile port worry might be unfounded depending on the device you are targeting. What will be a worry by converting everything to sprites is the sheer size of your spritesheets if you still want the game to resemble 3D despite being sprite based, and possible loss of performance from overdraw due to transparent pixels in your sprites.

    High texture sizes means more space consumed by your app. Mobile devices most likely work in max texture sizes of 1024x1024. Higher end devices today probably use 2048x2048, but it is still too little depending on the resolution you want your sprites to be in. To add to this all your animations will have 8 sides which means alot of spritesheets.

    Besides that your work pipeline will require an added step of turning all objects, characters+animations, into 8 sided spritesheets which is just added time and tedium, in addition to the current headache you have calculating what sprite to show depending on the rotation of the object.

    The costs far outweigh the benefit, and you should only proceed with this step if you are absolutely sure this is what you want, or if there is a significant performance gain, to using billboarded sprites.
     
  5. Ninekorn

    Ninekorn

    Joined:
    Aug 12, 2016
    Posts:
    66
    Very insightfull answer. I hadn't thought about a lot of what you said since I haven't ported anything to anything yet. I was using textures of 2048*2048 for the test. The thing is once the script is done I will have the opportunity to test it on lower end devices to see the performance and lower the sprites quality accordingly. But the thing I was worrying about was really the rotations in euler Angles or the relative points to calculate the 45 degrees incréments in script. As I said it is pretty tedious but I really want to give it a shot and see the result. Once the script is done it will be easier to just make the spritesheets... Also i know it might sound weird but for the moment I am using single sprites that are all gameObjects in the scene with their renderer disabled and I enable them once their rotation fits the requirements. I Wonder how much time it's going to take to see it come to fruition. Ill make spritesheets with GameCharacterHub once I am done with the script. Thanks a lot for your input Laperen. I really wish there was this kind of asset on the Unity asset store to convert a 2d sprite in a 3d motion.
     
  6. Laperen

    Laperen

    Joined:
    Feb 1, 2016
    Posts:
    1,065
    Have a parent object, with a child object constantly looking at the camera.
    The sprite will be placed in the child object.
    The difference in rotation between the parent and child will decide what sprite the child object should display.

    That's the simplest way I can think of to show bill-boarding in a 3D world as of now. I don't quite understand the need to account for X and Z axis rotations though. "Old Doom" as I recall did not allow any way to look up or down, only Y axis rotations had to be accounted for by the characters and items. As long as the viewpoint is at a consistent height level, the sprites don't need need to account for X and Z axis rotations. For 2.5D this is entirely dependent on whether you are going to use a perspective or orthographic camera. I can't see bill-boarding working for a perspective camera with free range, although I have gotten bill-boarding to work with orthographic.
     
  7. Ninekorn

    Ninekorn

    Joined:
    Aug 12, 2016
    Posts:
    66
    Hi Laperen thanks again for replying. What you offered as a solution is kinda what I was doing but with intent of doing it on all axis. Anyway here is the script so far. It makes it so that I can rotate a sprite on the Y Axis in a 360 kind of motion with 45 degrees incréments. If the skull is rotated higher than 45 degrees (or higher than 22.5 degrees or minus 22.5 degrees) the skull will disappear since all other 360 motions aren't coded yet. Anyone who wants to undertake the finishing of this script is "doomed" for wasting a LOT of hours on it. I'm still gonna try though. The script is already almost a thousand lines long and with 3 motions I think I was at 2000 lines.... Removed them since they weren't perfect yet.


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class rot2d3d: MonoBehaviour {
    6.  
    7.     float xPos;
    8.     float yPos;
    9.     public GameObject rotator;
    10.     float rotatorZPos;
    11.     float rotatorYPos;
    12.  
    13.     public SpriteRenderer yAxisskull0degreeRend;
    14.     public SpriteRenderer yAxisskull45degreeRend;
    15.     public SpriteRenderer yAxisskull90degreeRend;
    16.     public SpriteRenderer yAxisskull135degreeRend;
    17.     public SpriteRenderer yAxisskull180degreeRend;
    18.     public SpriteRenderer yAxisskull225degreeRend;
    19.     public SpriteRenderer yAxisskull270degreeRend;
    20.     public SpriteRenderer yAxisskull315degreeRend;
    21.  
    22.     bool yRot0to22 = false;
    23.     bool yRot22to45 = false;
    24.     bool yRot45to67 = false;
    25.     bool yRot67to90 = false;
    26.     bool yRot90to112 = false;
    27.     bool yRot112to135 = false;
    28.     bool yRot135to157 = false;
    29.     bool yRot157to180 = false;
    30.     bool yRot180to202 = false;
    31.     bool yRot202to225 = false;
    32.     bool yRot225to247 = false;
    33.     bool yRot247to270 = false;
    34.     bool yRot270to292 = false;
    35.     bool yRot292to315 = false;
    36.     bool yRot315to337 = false;
    37.     bool yRot337to360 = false;
    38.  
    39.  
    40.     bool xRot0to22 = false;
    41.     bool xRot22to45 = false;
    42.     bool xRot45to67 = false;
    43.     bool xRot67to90 = false;
    44.     bool xRot90to112 = false;
    45.     bool xRot112to135 = false;
    46.     bool xRot135to157 = false;
    47.     bool xRot157to180 = false;
    48.     bool xRot180to202 = false;
    49.     bool xRot202to225 = false;
    50.     bool xRot225to247 = false;
    51.     bool xRot247to270 = false;
    52.     bool xRot270to292 = false;
    53.     bool xRot292to315 = false;
    54.     bool xRot315to337 = false;
    55.     bool xRot337to360 = false;
    56.  
    57.  
    58.     bool zRot0to22 = false;
    59.     bool zRot22to45 = false;
    60.     bool zRot45to67 = false;
    61.     bool zRot67to90 = false;
    62.     bool zRot90to112 = false;
    63.     bool zRot112to135 = false;
    64.     bool zRot135to157 = false;
    65.     bool zRot157to180 = false;
    66.     bool zRot180to202 = false;
    67.     bool zRot202to225 = false;
    68.     bool zRot225to247 = false;
    69.     bool zRot247to270 = false;
    70.     bool zRot270to292 = false;
    71.     bool zRot292to315 = false;
    72.     bool zRot315to337 = false;
    73.     bool zRot337to360 = false;
    74.  
    75.  
    76.     bool zRotHigher360 = false;
    77.     bool zRotLower0 = false;
    78.     bool yRotHigher360 = false;
    79.     bool yRotLower0 = false;
    80.     bool xRotHigher360 = false;
    81.     bool xRotLower0 = false;
    82.  
    83.  
    84.  
    85.     void Start()
    86.     {
    87.  
    88.     }
    89.  
    90.  
    91.     void Update()
    92.     {
    93.      
    94.         if (rotator.transform.eulerAngles.y >= 0 && rotator.transform.eulerAngles.y < 22.5f)
    95.         {
    96.             yRot0to22 = true;
    97.         }
    98.         else
    99.         {
    100.             yRot0to22 = false;
    101.         }
    102.  
    103.         if (rotator.transform.eulerAngles.y >= 22.5f && rotator.transform.eulerAngles.y < 45)
    104.         {
    105.             yRot22to45 = true;
    106.         }
    107.         else
    108.         {
    109.             yRot22to45 = false;
    110.         }
    111.  
    112.  
    113.         if (rotator.transform.eulerAngles.y >= 45 && rotator.transform.eulerAngles.y < 67.5f)
    114.         {
    115.             yRot45to67 = true;
    116.         }
    117.         else
    118.         {
    119.             yRot45to67 = false;
    120.         }
    121.  
    122.         if (rotator.transform.eulerAngles.y >= 67.5 && rotator.transform.eulerAngles.y < 90)
    123.         {
    124.             yRot67to90 = true;
    125.         }
    126.         else
    127.         {
    128.             yRot67to90 = false;
    129.         }
    130.         if (rotator.transform.eulerAngles.y >= 90 && rotator.transform.eulerAngles.y < 112.5f)
    131.         {
    132.             yRot90to112 = true;
    133.         }
    134.         else
    135.         {
    136.             yRot90to112 = false;
    137.         }
    138.  
    139.         if (rotator.transform.eulerAngles.y >= 112.5f && rotator.transform.eulerAngles.y < 135)
    140.         {
    141.             yRot112to135 = true;
    142.         }
    143.         else
    144.         {
    145.             yRot112to135 = false;
    146.         }
    147.  
    148.         if (rotator.transform.eulerAngles.y >= 135 && rotator.transform.eulerAngles.y < 157.5)
    149.         {
    150.             yRot135to157 = true;
    151.         }
    152.         else
    153.         {
    154.             yRot135to157 = false;
    155.         }
    156.  
    157.         if (rotator.transform.eulerAngles.y >= 157.5f && rotator.transform.eulerAngles.y < 180)
    158.         {
    159.             yRot157to180 = true;
    160.         }
    161.         else
    162.         {
    163.             yRot157to180 = false;
    164.         }
    165.  
    166.  
    167.         if (rotator.transform.eulerAngles.y >= 180 && rotator.transform.eulerAngles.y < 202.5f)
    168.         {
    169.             yRot180to202 = true;
    170.         }
    171.         else
    172.         {
    173.             yRot180to202 = false;
    174.         }
    175.  
    176.         if (rotator.transform.eulerAngles.y >= 202.5f && rotator.transform.eulerAngles.y < 225)
    177.         {
    178.             yRot202to225 = true;
    179.         }
    180.         else
    181.         {
    182.             yRot202to225 = false;
    183.         }
    184.         if (rotator.transform.eulerAngles.y >= 225 && rotator.transform.eulerAngles.y < 247.5f)
    185.         {
    186.             yRot225to247 = true;
    187.         }
    188.         else
    189.         {
    190.             yRot225to247 = false;
    191.         }
    192.         if (rotator.transform.eulerAngles.y >= 247.5 && rotator.transform.eulerAngles.y < 270)
    193.         {
    194.             yRot247to270 = true;
    195.         }
    196.         else
    197.         {
    198.             yRot247to270 = false;
    199.         }
    200.  
    201.         if (rotator.transform.eulerAngles.y >= 270 && rotator.transform.eulerAngles.y < 292.5)
    202.         {
    203.             yRot270to292 = true;
    204.         }
    205.         else
    206.         {
    207.             yRot270to292 = false;
    208.         }
    209.         if (rotator.transform.eulerAngles.y >= 292.5 && rotator.transform.eulerAngles.y < 315)
    210.         {
    211.             yRot292to315 = true;
    212.         }
    213.         else
    214.         {
    215.             yRot292to315 = false;
    216.         }
    217.         if (rotator.transform.eulerAngles.y >= 315 && rotator.transform.eulerAngles.y < 337.5)
    218.         {
    219.             yRot315to337 = true;
    220.         }
    221.         else
    222.         {
    223.             yRot315to337 = false;
    224.         }
    225.         if (rotator.transform.eulerAngles.y >= 337.5f && rotator.transform.eulerAngles.y <= 360)
    226.         {
    227.             yRot337to360 = true;
    228.         }
    229.         else
    230.         {
    231.             yRot337to360 = false;
    232.         }
    233.  
    234.      
    235.  
    236.  
    237.         if (rotator.transform.eulerAngles.x >= 0 && rotator.transform.eulerAngles.x < 22.5f)
    238.         {
    239.             xRot0to22 = true;
    240.         }
    241.         else
    242.         {
    243.             xRot0to22 = false;
    244.         }
    245.  
    246.         if (rotator.transform.eulerAngles.x >= 22.5f && rotator.transform.eulerAngles.x < 45)
    247.         {
    248.             xRot22to45 = true;
    249.         }
    250.         else
    251.         {
    252.             xRot22to45 = false;
    253.         }
    254.  
    255.  
    256.         if (rotator.transform.eulerAngles.x >= 45 && rotator.transform.eulerAngles.x < 67.5f)
    257.         {
    258.             xRot45to67 = true;
    259.         }
    260.         else
    261.         {
    262.             xRot45to67 = false;
    263.         }
    264.  
    265.         if (rotator.transform.eulerAngles.x >= 67.5 && rotator.transform.eulerAngles.x < 90)
    266.         {
    267.             xRot67to90 = true;
    268.         }
    269.         else
    270.         {
    271.             xRot67to90 = false;
    272.         }
    273.         if (rotator.transform.eulerAngles.x >= 90 && rotator.transform.eulerAngles.x < 112.5f)
    274.         {
    275.             xRot90to112 = true;
    276.         }
    277.         else
    278.         {
    279.             xRot90to112 = false;
    280.         }
    281.  
    282.         if (rotator.transform.eulerAngles.x >= 112.5f && rotator.transform.eulerAngles.x < 135)
    283.         {
    284.             xRot112to135 = true;
    285.         }
    286.         else
    287.         {
    288.             xRot112to135 = false;
    289.         }
    290.  
    291.         if (rotator.transform.eulerAngles.x >= 135 && rotator.transform.eulerAngles.x < 157.5)
    292.         {
    293.             xRot135to157 = true;
    294.         }
    295.         else
    296.         {
    297.             xRot135to157 = false;
    298.         }
    299.  
    300.         if (rotator.transform.eulerAngles.x >= 157.5f && rotator.transform.eulerAngles.x < 180)
    301.         {
    302.             xRot157to180 = true;
    303.         }
    304.         else
    305.         {
    306.             xRot157to180 = false;
    307.         }
    308.  
    309.  
    310.         if (rotator.transform.eulerAngles.x >= 180 && rotator.transform.eulerAngles.x < 202.5f)
    311.         {
    312.             xRot180to202 = true;
    313.         }
    314.         else
    315.         {
    316.             xRot180to202 = false;
    317.         }
    318.  
    319.         if (rotator.transform.eulerAngles.x >= 202.5f && rotator.transform.eulerAngles.x < 225)
    320.         {
    321.             xRot202to225 = true;
    322.         }
    323.         else
    324.         {
    325.             xRot202to225 = false;
    326.         }
    327.         if (rotator.transform.eulerAngles.x >= 225 && rotator.transform.eulerAngles.x < 247.5f)
    328.         {
    329.             xRot225to247 = true;
    330.         }
    331.         else
    332.         {
    333.             xRot225to247 = false;
    334.         }
    335.         if (rotator.transform.eulerAngles.x >= 247.5 && rotator.transform.eulerAngles.x < 270)
    336.         {
    337.             xRot247to270 = true;
    338.         }
    339.         else
    340.         {
    341.             xRot247to270 = false;
    342.         }
    343.  
    344.         if (rotator.transform.eulerAngles.x >= 270 && rotator.transform.eulerAngles.x < 292.5)
    345.         {
    346.             xRot270to292 = true;
    347.         }
    348.         else
    349.         {
    350.             xRot270to292 = false;
    351.         }
    352.         if (rotator.transform.eulerAngles.x >= 292.5 && rotator.transform.eulerAngles.x < 315)
    353.         {
    354.             xRot292to315 = true;
    355.         }
    356.         else
    357.         {
    358.             xRot292to315 = false;
    359.         }
    360.         if (rotator.transform.eulerAngles.x >= 315 && rotator.transform.eulerAngles.x < 337.5)
    361.         {
    362.             xRot315to337 = true;
    363.         }
    364.         else
    365.         {
    366.             xRot315to337 = false;
    367.         }
    368.         if (rotator.transform.eulerAngles.x >= 337.5f && rotator.transform.eulerAngles.x <= 360)
    369.         {
    370.             xRot337to360 = true;
    371.         }
    372.         else
    373.         {
    374.             xRot337to360 = false;
    375.         }
    376.  
    377.         if (rotator.transform.eulerAngles.z >= 0 && rotator.transform.eulerAngles.z < 22.5f)
    378.         {
    379.             zRot0to22 = true;
    380.         }
    381.         else
    382.         {
    383.             zRot0to22 = false;
    384.         }
    385.  
    386.         if (rotator.transform.eulerAngles.z >= 22.5f && rotator.transform.eulerAngles.z < 45)
    387.         {
    388.             zRot22to45 = true;
    389.         }
    390.         else
    391.         {
    392.             zRot22to45 = false;
    393.         }
    394.  
    395.  
    396.         if (rotator.transform.eulerAngles.z >= 45 && rotator.transform.eulerAngles.z < 67.5f)
    397.         {
    398.             zRot45to67 = true;
    399.         }
    400.         else
    401.         {
    402.             zRot45to67 = false;
    403.         }
    404.  
    405.         if (rotator.transform.eulerAngles.z >= 67.5 && rotator.transform.eulerAngles.z < 90)
    406.         {
    407.             zRot67to90 = true;
    408.         }
    409.         else
    410.         {
    411.             zRot67to90 = false;
    412.         }
    413.         if (rotator.transform.eulerAngles.z >= 90 && rotator.transform.eulerAngles.z < 112.5f)
    414.         {
    415.             zRot90to112 = true;
    416.         }
    417.         else
    418.         {
    419.             zRot90to112 = false;
    420.         }
    421.  
    422.         if (rotator.transform.eulerAngles.z >= 112.5f && rotator.transform.eulerAngles.z < 135)
    423.         {
    424.             zRot112to135 = true;
    425.         }
    426.         else
    427.         {
    428.             zRot112to135 = false;
    429.         }
    430.  
    431.         if (rotator.transform.eulerAngles.z >= 135 && rotator.transform.eulerAngles.z < 157.5)
    432.         {
    433.             zRot135to157 = true;
    434.         }
    435.         else
    436.         {
    437.             zRot135to157 = false;
    438.         }
    439.  
    440.         if (rotator.transform.eulerAngles.z >= 157.5f && rotator.transform.eulerAngles.z < 180)
    441.         {
    442.             zRot157to180 = true;
    443.         }
    444.         else
    445.         {
    446.             zRot157to180 = false;
    447.         }
    448.  
    449.  
    450.         if (rotator.transform.eulerAngles.z >= 180 && rotator.transform.eulerAngles.z < 202.5f)
    451.         {
    452.             zRot180to202 = true;
    453.         }
    454.         else
    455.         {
    456.             zRot180to202 = false;
    457.         }
    458.  
    459.         if (rotator.transform.eulerAngles.z >= 202.5f && rotator.transform.eulerAngles.z < 225)
    460.         {
    461.             zRot202to225 = true;
    462.         }
    463.         else
    464.         {
    465.             zRot202to225 = false;
    466.         }
    467.         if (rotator.transform.eulerAngles.z >= 225 && rotator.transform.eulerAngles.z < 247.5f)
    468.         {
    469.             zRot225to247 = true;
    470.         }
    471.         else
    472.         {
    473.             zRot225to247 = false;
    474.         }
    475.         if (rotator.transform.eulerAngles.z >= 247.5 && rotator.transform.eulerAngles.z < 270)
    476.         {
    477.             zRot247to270 = true;
    478.         }
    479.         else
    480.         {
    481.             zRot247to270 = false;
    482.         }
    483.  
    484.         if (rotator.transform.eulerAngles.z >= 270 && rotator.transform.eulerAngles.z < 292.5)
    485.         {
    486.             zRot270to292 = true;
    487.         }
    488.         else
    489.         {
    490.             zRot270to292 = false;
    491.         }
    492.         if (rotator.transform.eulerAngles.z >= 292.5 && rotator.transform.eulerAngles.z < 315)
    493.         {
    494.             zRot292to315 = true;
    495.         }
    496.         else
    497.         {
    498.             zRot292to315 = false;
    499.         }
    500.         if (rotator.transform.eulerAngles.z >= 315 && rotator.transform.eulerAngles.z < 337.5)
    501.         {
    502.             zRot315to337 = true;
    503.         }
    504.         else
    505.         {
    506.             zRot315to337 = false;
    507.         }
    508.         if (rotator.transform.eulerAngles.z >= 337.5f && rotator.transform.eulerAngles.z <= 360)
    509.         {
    510.             zRot337to360 = true;
    511.         }
    512.         else
    513.         {
    514.             zRot337to360 = false;
    515.         }
    516.  
    517.         if (rotator.transform.eulerAngles.y > 360)
    518.         {
    519.             Debug.Log("rotY>360" + " " + rotator.transform.eulerAngles.y);
    520.             yRotHigher360 = true;
    521.         }
    522.         else
    523.         {
    524.             yRotHigher360 = false;
    525.         }
    526.         if (rotator.transform.eulerAngles.y < 0)
    527.         {
    528.             Debug.Log("rotY<0" + " " + rotator.transform.eulerAngles.y);
    529.             yRotLower0 = true;
    530.         }
    531.         else
    532.         {
    533.             yRotLower0 = false;
    534.         }
    535.  
    536.         if(rotator.transform.eulerAngles.x > 360)
    537.         {
    538.             Debug.Log("rotx>360" + " " + rotator.transform.eulerAngles.x);
    539.             xRotHigher360 = true;
    540.         }
    541.         else
    542.         {
    543.             xRotHigher360 = false;
    544.         }
    545.  
    546.         if (rotator.transform.eulerAngles.x < 0)
    547.         {
    548.             Debug.Log("rotx<0" + " " + rotator.transform.eulerAngles.x);
    549.             xRotLower0 = true;
    550.         }
    551.         else
    552.         {
    553.             xRotLower0 = false;
    554.         }
    555.  
    556.         if (rotator.transform.eulerAngles.z > 360)
    557.         {
    558.             Debug.Log("rotz>360" + " " + rotator.transform.eulerAngles.z);
    559.  
    560.             zRotHigher360 = true;
    561.         }
    562.         else
    563.         {
    564.             zRotHigher360 = false;
    565.         }
    566.         if (rotator.transform.eulerAngles.z < 0)
    567.         {
    568.             Debug.Log("rotz<0" + " " + rotator.transform.eulerAngles.z);
    569.             zRotLower0 = true;
    570.         }
    571.         else
    572.         {
    573.             zRotLower0 = false;
    574.         }
    575.         /////////////////////////////////////ROTATION ON Y AXIS///////////////////////////////////////////
    576.         if (xRot0to22 && yRot0to22 && zRot0to22 ||
    577.             xRot0to22 && yRot337to360 && zRot0to22||
    578.             xRot0to22 && yRot0to22 && zRot337to360 ||
    579.             xRot337to360 && yRot0to22 && zRot0to22 ||
    580.             xRot0to22 && yRot337to360 && zRot337to360||
    581.             xRot337to360 && yRot0to22 && zRot337to360||
    582.             xRot337to360 && yRot337to360 && zRot0to22||
    583.             xRot337to360 && yRot337to360 && zRotLower0||
    584.             xRot337to360 && yRot337to360 && zRot337to360||
    585.             xRot0to22 && yRot337to360 && zRotLower0||
    586.             xRot0to22 && yRot0to22 && zRotLower0)
    587.         {
    588.             yAxisskull0degreeRend.enabled = false;
    589.             yAxisskull45degreeRend.enabled = false;
    590.             yAxisskull90degreeRend.enabled = false;
    591.             yAxisskull135degreeRend.enabled = false;
    592.             yAxisskull180degreeRend.enabled = true;
    593.             yAxisskull225degreeRend.enabled = false;
    594.             yAxisskull270degreeRend.enabled = false;
    595.             yAxisskull315degreeRend.enabled = false;
    596.  
    597.         }
    598.  
    599.         else if (xRot0to22 && yRot22to45 && zRot0to22 ||
    600.                 xRot0to22 && yRot45to67 && zRot0to22 ||
    601.                 xRot337to360 && yRot22to45 && zRot0to22||
    602.                 xRot337to360 && yRot22to45 && zRotLower0||
    603.                 xRot0to22 && yRot22to45 && zRotLower0 ||
    604.                 xRot337to360 && yRot45to67 && zRot0to22||
    605.                 xRot0to22 && yRot22to45 && zRot337to360||
    606.                 xRotLower0 && yRot22to45 && zRot0to22||
    607.                 xRot0to22 && yRot45to67 && zRot337to360||
    608.                 xRotLower0 && yRot45to67&& zRot337to360||
    609.                 xRotLower0 && yRot22to45 && zRot337to360||
    610.                 xRotLower0 && yRot45to67 && zRot0to22||
    611.                 xRot337to360 && yRot45to67 && zRot337to360||
    612.                 xRot337to360 && yRot22to45 && zRot337to360||
    613.                 xRot0to22 && yRot45to67&& zRotLower0||
    614.                 xRot337to360 && yRot45to67 && zRotLower0)
    615.         {
    616.             yAxisskull0degreeRend.enabled = false;
    617.             yAxisskull45degreeRend.enabled = false;
    618.             yAxisskull90degreeRend.enabled = false;
    619.             yAxisskull135degreeRend.enabled = true;
    620.             yAxisskull180degreeRend.enabled = false;
    621.             yAxisskull225degreeRend.enabled = false;
    622.             yAxisskull270degreeRend.enabled = false;
    623.             yAxisskull315degreeRend.enabled = false;
    624.         }
    625.  
    626.         else if (xRot0to22 && yRot67to90 && zRot0to22 ||
    627.            xRot0to22 && yRot90to112 && zRot0to22 ||
    628.            xRot0to22 && yRot90to112 && zRot337to360||
    629.            xRot0to22 && yRot67to90 && zRot337to360||
    630.            xRotLower0 && yRot67to90 && zRot0to22||
    631.            xRotLower0 && yRot67to90 && zRot337to360||
    632.            xRotLower0 && yRot90to112 && zRot0to22||
    633.            xRotLower0 && yRot90to112 && zRot337to360||
    634.            xRot337to360 && yRot90to112 && zRot0to22||
    635.            xRot0to22 && yRot90to112 && zRotLower0||
    636.            xRot337to360 && yRot67to90 && zRot0to22||
    637.            xRot0to22 && yRot67to90 && zRotLower0||
    638.            xRot337to360 && yRot90to112 && zRotLower0||
    639.            xRot337to360 && yRot90to112 && zRot337to360||
    640.            xRot337to360 && yRot67to90 && zRot337to360)
    641.          
    642.         {
    643.             yAxisskull0degreeRend.enabled = false;
    644.             yAxisskull45degreeRend.enabled = false;
    645.             yAxisskull90degreeRend.enabled = true;
    646.             yAxisskull135degreeRend.enabled = false;
    647.             yAxisskull180degreeRend.enabled = false;
    648.             yAxisskull225degreeRend.enabled = false;
    649.             yAxisskull270degreeRend.enabled = false;
    650.             yAxisskull315degreeRend.enabled = false;      
    651.         }
    652.  
    653.         else if (xRot0to22 && yRot112to135 && zRot0to22 ||
    654.           xRot0to22 && yRot135to157 && zRot0to22||
    655.           xRot0to22 && yRot135to157 && zRot337to360||
    656.           xRot0to22 && yRot135to157 && zRotLower0||
    657.           xRot337to360 && yRot135to157&& zRotLower0||
    658.           xRot0to22 && yRot112to135 && zRotLower0||
    659.           xRot337to360 && yRot112to135 && zRot0to22||
    660.           xRot337to360 && yRot112to135 && zRot337to360||
    661.           xRotLower0 && yRot112to135 && zRot337to360||
    662.           xRotLower0 && yRot135to157 && zRot337to360||
    663.           xRot0to22 && yRot112to135 && zRot337to360||
    664.           xRotLower0 && yRot112to135 && zRot0to22)
    665.         {
    666.             yAxisskull0degreeRend.enabled = false;
    667.             yAxisskull45degreeRend.enabled = true;
    668.             yAxisskull90degreeRend.enabled = false;
    669.             yAxisskull135degreeRend.enabled = false;
    670.             yAxisskull180degreeRend.enabled = false;
    671.             yAxisskull225degreeRend.enabled = false;
    672.             yAxisskull270degreeRend.enabled = false;
    673.             yAxisskull315degreeRend.enabled = false;        
    674.         }
    675.  
    676.         else if (xRot0to22 && yRot157to180 && zRot0to22 ||
    677.           xRot0to22 && yRot180to202 && zRot0to22||
    678.           xRot0to22&& yRot157to180 && zRotLower0||
    679.           xRot337to360 && yRot157to180 && zRot0to22||
    680.           xRot337to360 && yRot157to180 && zRotLower0||
    681.           xRotLower0 && yRot157to180 && zRot0to22||
    682.           xRot337to360 && yRot157to180 && zRot337to360||
    683.           xRot0to22 && yRot157to180 && zRot337to360||
    684.           xRotLower0 && yRot180to202 && zRotLower0||
    685.           xRot337to360 && yRot180to202 && zRotLower0||
    686.           xRot337to360 && yRot180to202 && zRot0to22||
    687.           xRot0to22 && yRot180to202 && zRotLower0||
    688.           xRot337to360 && yRot180to202 && zRot337to360||
    689.           xRot0to22 && yRot180to202 && zRot337to360||
    690.           xRotLower0 && yRot180to202 && zRot0to22||
    691.           xRotLower0 && yRot180to202 && zRot337to360||
    692.           xRotLower0 && yRot157to180 && zRot337to360)
    693.         {
    694.             yAxisskull0degreeRend.enabled = true;
    695.             yAxisskull45degreeRend.enabled = false;
    696.             yAxisskull90degreeRend.enabled = false;
    697.             yAxisskull135degreeRend.enabled = false;
    698.             yAxisskull180degreeRend.enabled = false;
    699.             yAxisskull225degreeRend.enabled = false;
    700.             yAxisskull270degreeRend.enabled = false;
    701.             yAxisskull315degreeRend.enabled = false;
    702.         }
    703.  
    704.  
    705.         else if (xRot0to22 && yRot202to225 && zRot0to22 ||
    706.           xRot0to22 && yRot225to247 && zRot0to22||
    707.           xRot0to22 && yRot225to247 && zRotLower0||
    708.           xRot0to22 && yRot202to225 && zRotLower0||
    709.           xRotLower0 && yRot202to225 && zRot0to22||
    710.           xRotLower0 && yRot225to247 && zRot0to22||
    711.           xRot0to22 && yRot225to247 && zRot337to360||
    712.           xRotLower0 && yRot225to247 && zRot337to360||
    713.           xRot337to360 && yRot225to247 && zRot0to22||
    714.           xRotLower0 && yRot202to225 && zRot337to360||
    715.           xRot337to360 && yRot225to247 && zRot337to360||
    716.           xRot337to360 && yRot225to247 && zRotLower0||
    717.           xRot0to22 && yRot202to225 && zRot337to360||
    718.           xRot337to360 && yRot202to225 && zRot0to22||
    719.           xRot337to360 && yRot202to225 && zRotLower0||
    720.           xRot337to360 && yRot202to225 && zRot337to360)
    721.         {
    722.             yAxisskull0degreeRend.enabled = false;
    723.             yAxisskull45degreeRend.enabled = false;
    724.             yAxisskull90degreeRend.enabled = false;
    725.             yAxisskull135degreeRend.enabled = false;
    726.             yAxisskull180degreeRend.enabled = false;
    727.             yAxisskull225degreeRend.enabled = false;
    728.             yAxisskull270degreeRend.enabled = false;
    729.             yAxisskull315degreeRend.enabled = true;        
    730.         }
    731.         else if (xRot0to22 && yRot247to270 && zRot0to22 ||
    732.                  xRot0to22 && yRot270to292 && zRot0to22||
    733.                  xRot0to22 && yRot247to270 && zRot337to360 ||
    734.                  xRot337to360 && yRot247to270 && zRot0to22||
    735.                  xRot337to360 && yRot270to292 && zRotLower0||
    736.                  xRot0to22 && yRot270to292 && zRotLower0||
    737.                  xRot337to360 && yRot270to292 && zRot0to22||
    738.                  xRot337to360 && yRot270to292 && zRot337to360||
    739.                  xRot337to360 && yRot247to270 && zRotLower0||
    740.                  xRot0to22 && yRot247to270 && zRotLower0||
    741.                  xRot337to360 && yRot247to270 && zRot337to360||
    742.                  xRotLower0 && yRot247to270 && zRot337to360||
    743.                  xRotLower0 && yRot247to270 && zRot0to22||
    744.                  xRot0to22 && yRot270to292 && zRot337to360||
    745.                  xRotLower0 && yRot270to292 && zRot0to22||
    746.                  xRotLower0 && yRot270to292 && zRot337to360)
    747.         {
    748.             yAxisskull0degreeRend.enabled = false;
    749.             yAxisskull45degreeRend.enabled = false;
    750.             yAxisskull90degreeRend.enabled = false;
    751.             yAxisskull135degreeRend.enabled = false;
    752.             yAxisskull180degreeRend.enabled = false;
    753.             yAxisskull225degreeRend.enabled = false;
    754.             yAxisskull270degreeRend.enabled = true;
    755.             yAxisskull315degreeRend.enabled = false;        
    756.         }
    757.  
    758.         else if (xRot0to22 && yRot292to315 && zRot0to22 ||
    759.         xRot0to22 && yRot315to337 && zRot0to22||
    760.         xRot337to360 && yRot315to337 && zRotLower0||
    761.         xRot0to22 && yRot315to337 && zRotLower0||
    762.         xRot337to360 && yRot315to337 && zRot0to22||
    763.         xRot0to22 && yRot292to315 && zRotLower0||
    764.         xRot337to360 && yRot292to315 && zRotLower0||
    765.         xRot337to360 && yRot315to337 && zRot337to360||
    766.         xRot337to360 && yRot292to315 && zRot337to360||
    767.         xRotLower0 && yRot315to337 && zRot0to22||
    768.         xRot0to22 && yRot315to337 && zRot337to360||
    769.         xRot337to360 && yRot292to315 && zRot0to22||
    770.         xRot0to22 && yRot292to315 && zRot337to360||
    771.         xRotLower0 && yRot292to315 && zRot0to22||
    772.         xRotLower0 && yRot292to315 && zRot337to360||
    773.         xRotLower0 && yRot315to337 && zRot337to360)
    774.         {
    775.             yAxisskull0degreeRend.enabled = false;
    776.             yAxisskull45degreeRend.enabled = false;
    777.             yAxisskull90degreeRend.enabled = false;
    778.             yAxisskull135degreeRend.enabled = false;
    779.             yAxisskull180degreeRend.enabled = false;
    780.             yAxisskull225degreeRend.enabled = true;
    781.             yAxisskull270degreeRend.enabled = false;
    782.             yAxisskull315degreeRend.enabled = false;
    783.         }
    784.    
    785.         else
    786.         {
    787.             yAxisskull0degreeRend.enabled = false;
    788.             yAxisskull45degreeRend.enabled = false;
    789.             yAxisskull90degreeRend.enabled = false;
    790.             yAxisskull135degreeRend.enabled = false;
    791.             yAxisskull180degreeRend.enabled = false;
    792.             yAxisskull225degreeRend.enabled = false;
    793.             yAxisskull270degreeRend.enabled = false;
    794.             yAxisskull315degreeRend.enabled = false;          
    795.         }
    796.  
    797.         if (yRot0to22 == true)
    798.         {
    799.             Debug.Log(yRot0to22);
    800.         }
    801.         if (yRot22to45 == true)
    802.         {
    803.             Debug.Log(yRot22to45);
    804.         }
    805.         if (yRot45to67 == true)
    806.         {
    807.             Debug.Log(yRot45to67);
    808.         }
    809.         if (yRot67to90 == true)
    810.         {
    811.             Debug.Log(yRot67to90);
    812.         }
    813.         if (yRot90to112 == true)
    814.         {
    815.             Debug.Log(yRot90to112);
    816.         }
    817.         if (yRot112to135 == true)
    818.         {
    819.             Debug.Log(yRot112to135);
    820.         }
    821.         if (yRot135to157 == true)
    822.         {
    823.             Debug.Log(yRot135to157);
    824.         }
    825.         if (yRot157to180 == true)
    826.         {
    827.             Debug.Log(yRot157to180);
    828.         }
    829.         if (yRot180to202 == true)
    830.         {
    831.             Debug.Log(yRot180to202);
    832.         }
    833.         if (yRot202to225 == true)
    834.         {
    835.             Debug.Log(yRot202to225);
    836.         }
    837.         if (yRot225to247 == true)
    838.         {
    839.             Debug.Log(yRot225to247);
    840.         }
    841.         if (yRot247to270 == true)
    842.         {
    843.             Debug.Log(yRot247to270);
    844.         }
    845.         if (yRot270to292 == true)
    846.         {
    847.             Debug.Log(yRot270to292);
    848.         }
    849.         if (yRot292to315 == true)
    850.         {
    851.             Debug.Log(yRot292to315);
    852.         }
    853.         if (yRot315to337 == true)
    854.         {
    855.             Debug.Log(yRot315to337);
    856.         }
    857.         if (yRot337to360 == true)
    858.         {
    859.             Debug.Log(yRot337to360);
    860.         }
    861.  
    862.         if (xRot0to22 == true)
    863.         {
    864.             Debug.Log(xRot0to22);
    865.         }
    866.         if (xRot22to45 == true)
    867.         {
    868.             Debug.Log(xRot22to45);
    869.         }
    870.         if (xRot45to67 == true)
    871.         {
    872.             Debug.Log(xRot45to67);
    873.         }
    874.         if (xRot67to90 == true)
    875.         {
    876.             Debug.Log(xRot67to90);
    877.         }
    878.         if (xRot90to112 == true)
    879.         {
    880.             Debug.Log(xRot90to112);
    881.         }
    882.         if (xRot112to135 == true)
    883.         {
    884.             Debug.Log(xRot112to135);
    885.         }
    886.         if (xRot135to157 == true)
    887.         {
    888.             Debug.Log(xRot135to157);
    889.         }
    890.         if (xRot157to180 == true)
    891.         {
    892.             Debug.Log(xRot157to180);
    893.         }
    894.         if (xRot180to202 == true)
    895.         {
    896.             Debug.Log(xRot180to202);
    897.         }
    898.         if (xRot202to225 == true)
    899.         {
    900.             Debug.Log(xRot202to225);
    901.         }
    902.         if (xRot225to247 == true)
    903.         {
    904.             Debug.Log(xRot225to247);
    905.         }
    906.         if (xRot247to270 == true)
    907.         {
    908.             Debug.Log(xRot247to270);
    909.         }
    910.         if (xRot270to292 == true)
    911.         {
    912.             Debug.Log(xRot270to292);
    913.         }
    914.         if (xRot292to315 == true)
    915.         {
    916.             Debug.Log(xRot292to315);
    917.         }
    918.         if (xRot315to337 == true)
    919.         {
    920.             Debug.Log(xRot315to337);
    921.         }
    922.         if (xRot337to360 == true)
    923.         {
    924.             Debug.Log(xRot337to360);
    925.         }
    926.  
    927.         if (zRot0to22 == true)
    928.         {
    929.             Debug.Log(zRot0to22);
    930.         }
    931.         if (zRot22to45 == true)
    932.         {
    933.             Debug.Log(zRot22to45);
    934.         }
    935.         if (zRot45to67 == true)
    936.         {
    937.             Debug.Log(zRot45to67);
    938.         }
    939.         if (zRot67to90 == true)
    940.         {
    941.             Debug.Log(zRot67to90);
    942.         }
    943.         if (zRot90to112 == true)
    944.         {
    945.             Debug.Log(zRot90to112);
    946.         }
    947.         if (zRot112to135 == true)
    948.         {
    949.             Debug.Log(zRot112to135);
    950.         }
    951.         if (zRot135to157 == true)
    952.         {
    953.             Debug.Log(zRot135to157);
    954.         }
    955.         if (zRot157to180 == true)
    956.         {
    957.             Debug.Log(zRot157to180);
    958.         }
    959.         if (zRot180to202 == true)
    960.         {
    961.             Debug.Log(zRot180to202);
    962.         }
    963.         if (zRot202to225 == true)
    964.         {
    965.             Debug.Log(zRot202to225);
    966.         }
    967.         if (zRot225to247 == true)
    968.         {
    969.             Debug.Log(zRot225to247);
    970.         }
    971.         if (zRot247to270 == true)
    972.         {
    973.             Debug.Log(zRot247to270);
    974.         }
    975.         if (zRot270to292 == true)
    976.         {
    977.             Debug.Log(zRot270to292);
    978.         }
    979.         if (zRot292to315 == true)
    980.         {
    981.             Debug.Log(zRot292to315);
    982.         }
    983.         if (zRot315to337 == true)
    984.         {
    985.             Debug.Log(zRot315to337);
    986.         }
    987.         if (zRot337to360 == true)
    988.         {
    989.             Debug.Log(zRot337to360);
    990.         }
    991.     }
    992. }
    993.  
     
  8. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    Anytime you find yourself copying and pasting tons of variables like that, you desperately need to be using arrays, and I strongly recommend you watch a tutorial on arrays before writing a single additional line of code for anything - arrays are one of the most fundamental techniques of programming and useful in solving many, many problems. Besides the arrays, you're also writing incredibly inefficient and unreliable code thanks to your reliance on the slow, unpredictable .transform.eulerAngles. If you're dead set on this sprite thing, those are some problems you'll need to address, and I'd be willing to help you with that.

    But....

    I'm going to reiterate the original suggestion that you go ahead an use the original mesh and not this sprite generation method.

    This is wrong on many levels. Sprites have a few less triangles, but A) probably not as few as you think, and B) this doesn't make any difference you will ever notice.

    You seem to be under the impression that 2D sprites are considerably more efficient than rendering a mesh, and this simply isn't the case unless you really know what you're doing (and from the looks of this script, you don't) - and even when they're more efficient, it's only by a fraction. Rendered sprites take a lot more memory than the mesh will, and will not save you any rendering/processing power. If you don't understand why that is, here is what the mesh looks like for a simple sprite. It's not that much less complex in terms of vertices than your original mesh is, and when you're talking about mesh rendering, the overhead for rendering a mesh is such that rendering a 10-vertex mesh and a 2000-vertex mesh are virtually identical in terms of performance.

    (2D graphics can be more efficient with correct usage of sprite atlases, as they will pool many sprite meshes into one draw call, but if the code above is any indication, I don't think there is any chance that that is being done. And with the amount of trouble you're going to for this concept, you could far more easily write a script that uses mesh particles, which would give you the same benefit as you could get with sprites.)

    And for the sake of clarity, I'm not simply saying, "you shouldn't do this because you're doing it wrong" - after all, you came to the forums to improve that. What I'm saying is, you shouldn't do this. Let's say you watch a bunch of tutorials, learn to rewrite your script above to make it super-efficient. That would be trading memory efficiency for processing power efficiency. You'd be making your game take, I'm guessing, at least 15 times more memory on textures, for a tiny tiny amount less graphics processing time. You should pay more attention to your target platform: smartphones, especially those within the last 5 years or so, have really fast processors, but are still very limited in RAM. You're picking the smallest bottleneck, and squeezing more crap through that bottleneck.

    Abandon this effort. You're making everything worse and expending a hell of a lot of effort doing it.
     
  9. Ninekorn

    Ninekorn

    Joined:
    Aug 12, 2016
    Posts:
    66
    Thanks for replying Starmanta!

    Depending on the code I write I might not use arrays right away as for example in this script because rotations is something I have never touched that much before. I know arrays but sometimes I prefer writing a draft code with all the code upfront for me to see. But at some point like I always do I rewrite my whole script and get rid of what I don't want or simply shrink the whole thing up so that it is more reliable and faster. So i'm right down at the beginning with this code that's why it looks so newbish.

    Yes I am dead set on making this work. I want something special for my game but you are right about the Euler Angles. I have tried a lot of different setup like for example I was using the Mathf.Clamp method to clamp EulerAngles to the range I thought they should be in for my next Sprite to show Up and even then I always get in trouble when I do a 360 rotation of the X Axis. The thing is so complicated and completely unintuitive .... The Z Axis and Y Axis 360 motion are easier and i've been stuck even with my new script (which is as awfull as the first one) before trying the 360 motions on 45 degree Angles on each Axis. So yeah I desperately need a new strategy but I don't want to give up on this idea and i don't want to shelve it yet. So if you are willing to help, how else then using Euler Angles can I control or "Limit" a rotation? I think I'm done for tonight trying to make the Euler Angles work since they probably won't ever work and I'm gonna go read some more on Quaternions and Rotations and whatnot. Oh I tried using the Mouse Orbit Improved Script found on Unify Wiki but again this is about euler Angles and clamping them. It doesn't seem to always work as this is what I have been trying today and i failed terribly.
     
  10. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    As it happens, I (a long time ago, before the Sprite class even existed, and before a number of improvements to the Unity engine that make this a little redundant) have written a script that does pretty much exactly what you're doing - the intention was to be able to have a swarm of thousands of objects efficiently rendered. I was ultimately able to get mine to show about 5-10,000 objects onscreen, on a 2006 computer, while maintaining 60fps. That scenario is where this sort of situation might actually be worth it.

    So, here's the benefit of that experience.

    First piece of advice: When you're determining which image to show, the only piece of information you need is the position of the camera in the skull's local space. That's all. You can use transform.InverseTransformPoint(Camera.position) to get this. Once you have that, you'll want to convert this to coordinates by rotation: one axis around horizontally, one up and down vertically. Think latitude and longitude. The exact math involved Mathf.Atan2 (read up on the docs to understand how I did it below; while my code is pretty close to correct, it might need a little adjustment, as it's fully untested).

    Those two coordinates are all you need to decide on the sprite. No Quaternions or Euler Angles necessary at all. You're currently rendering sprites in three axes - that's actually unnecessary, because on one of those axes, you can just rotate the sprite itself! You can use the object's transform.up to work out how you need to rotate it. (for this one, you'll need to use Quaternions, but you should use .AngleAxis to create the rotation. Continue to not use Euler angles, they're terrible for literally any scenario except for typing rotations into the inspector)

    Back to picking an image. So you have two coordinates, and each of these will be associated with one dimension of an array of images. When I made this system, I had to use a grid on a texture. Taking advantage of the Sprite system will help you make this look better, but envisioning these images on a grid will help you figure out the logic. In your case, you'll want to render each picture into its own image. Once you have this sprite image, (this is critical), you need to make sure that they're all on the same atlas by changing their Packing Tag. This way, the sprites will be packed into one atlas image, which has two advantages. One, they can pack efficiently and save a little texture memory by not having to store all the empty space around the object. And two, and far more importantly, being packed in the same texture means they will all use the same draw call. This, by the way, is the only way that sprites are ever more efficient to render than a 3D mesh: because the game engine combines them all into a single mesh when it renders.

    So when you have these Sprites, you need to load them into a two-dimensional array so that your script knows how to access them. These two dimensions are associated with your two coordinates from above. I noticed in your existing code you have a bunch of SpriteRenderers; don't do that. Just use one SpriteRenderer per skull, and change its Sprite. Additionally, you want your SpriteRenderer to be a child object of your skull; this will allow you to rotate the SpriteRenderer to match the camera while your skull is still at its "real" rotation.

    Code (csharp):
    1. public Sprite[,] renderedImages;
    2. public int columns = 8; //this will give you 45-degree increments (360 degrees around)
    3. public int rows = 4; //again, 45-degree increments - remember, you only need 180 degrees (90 up and down)
    4.  
    5. //you might do this in Start, or as part of the asset setup in editor mode.
    6. void PopulateSpriteArray() {
    7. renderedImages = new Sprite[columns, rows];
    8. for (int xIndex=0;xIndex < columns;xIndex++) {
    9. for (int yIndex=0;yIndex < rows;yIndex++) {
    10. float latitudeAngle = 360f * xIndex / columns; //in this case, 45
    11. float longitudeAngle = 180f * yIndex / rows - 90f;
    12. float vertSinMult = Mathf.Sin(longitudeAngle);
    13. Vector3 cameraPosition = new Vector3(Mathf.Cos(latitudeAngle) * vertSinMult, Mathf.Cos(longitudeAngle)  , Mathf.Sin(latitudeAngle) * vertSinMult); //This transforms latitude and longitude into Cartesian coordinates
    14. //Insert "render sprite from this angle" code here. Position your camera at cameraPosition * some distance to render it, then get it into a Sprite however you see fit. This part is left as an exercise for the reader.
    15. Sprite yourResultingSprite = whatever;
    16. renderedImages[xIndex, yIndex] = yourResultingSprite;
    17. }
    18. }
    19. }
    20.  
    So that covers creating the array. For picking an image out of the array, you need to reverse the process. You need to be able to convert Cartesian coordinates back into lat/long, then use these to pick your index in the array.
    Code (csharp):
    1. Sprite GetSpriteForCameraPosition(Vector3 cameraWorldPos) {
    2. Vector3 cameraLocalVector = transform.InverseTransformPoint(cameraWorldPos).normalized;
    3. float lateralLength = (new Vector2(cameraLocalVector.x, cameraLocalVector.z) ).magnitude; //to be used as the "x" in the longitude's Mathf.Atan2
    4. float latitude = Mathf.Atan2(cameraLocalVector.z, cameraLocalVector.x) * Mathf.Rad2Deg;
    5. float longitude = Mathf.Atan2(cameraLocalVector.y, lateralLength) * Mathf.Rad2Deg; //this might be off by 90 or 180 or something, I don't remember. Do some experimenting to confirm. This should ultimately end up in a -90 to 90 range.
    6. // Now, here's the part where you skip all those lists of variables and bools you had.
    7. int latitudeIndex = Mathf.FloorToInt(latitude / 360f * rows);
    8. int longitudeIndex = Mathf.FloorToInt( (longitude / 180f + 90f) * columns);
    9. mySpriteRenderer.sprite = renderedImages[latitudeIndex, longitudeIndex];
    Neither of these pieces of code should be blindly copied and pasted into your script. I mean, you can copy and paste them, but make sure you read through them and understand what's going on. This is not a complete system by any stretch, and you will need to understand what's happening in order to complete it. And some of the math might be a certain amount of degrees off in one direction or another; again, untested code.

    A bit of a review of the things in your original script that this avoids:
    1. Lots of copied and pasted code. Learning the use of arrays, like I said, is critical. In this case, not only does using the latitude/longitude system avoid all that copying and pasting, but it makes it absolutely trivial to change your 45 degrees to more or fewer degrees; you can even change this amount per-object, so your skulls can be rendered at 15-degree intervals while other less important objects get 90 degree intervals.
    2. Euler angles. As I said, Euler angles are pretty much only the right answer when a person is typing rotations into the inspector. If you're doing any sort of logic, don't use them.
    3. Large numbers of SpriteRenderers. Use a single SR per skull, and just change its .sprite.

    If you need more help, I'll be happy to answer questions and help diagnose issues, but be advised that if your question was already covered in this post or in the linked documentation, I'm abandoning ship. Do not just copy and paste the code and then ask me to fix errors, or I'm out. Read the whole comment as many times as you need to to understand it.
     
    Last edited: Mar 9, 2017
  11. Ninekorn

    Ninekorn

    Joined:
    Aug 12, 2016
    Posts:
    66
    I have been getting on it. Seriously I cannot thank you enough. This is a way different approach then what I was trying but I can also definitely say it is a way better approach. Anyway I'm really confused about some stuff but I'm digging into everything you shared.

    Ill report back once I get somewhere will all of your info.
     
  12. Ninekorn

    Ninekorn

    Joined:
    Aug 12, 2016
    Posts:
    66
    Hi,
    I've been digging at it. but things are quite messy.
    So I have been able to convert cartesian coordinates to polar or spherical coordinates from a project someone posted on the Unity Forums found here at the bottom where it says "I'll just go ahead and do it,".
    http://answers.unity3d.com/questions/189724/polar-spherical-coordinates-to-xyz-and-vice-versa.html

    I applied his project to my script and now I can debug the Polar Coordinates. I'm using the InverseTransformPoint on the parent Object of the skull and the Camera.transform.position . I can see the coordinates in my debug window and also I debug a Raycast that shows me approx on what "triangles" of a (Primitive type found here http://wiki.unity3d.com/index.php/ProceduralPrimitives#C.23_-_Sphere) that the raycast goes through when I rotate that sphere. This "lat/long" sphere has lattitude and Longitude like triangles edges so it is a good visual helper.

    So at 0 deg Y rotation and 360 degree X Axis Rotation the "mapping" of the sprites is quite easy. But when I do this 45 degree rot on the y axis and then a 360 rot on the X Axis this is where things go haywire. The sprite mapping is not the same. I hadn't really thought about that but the mapping of the sprites is on the SAME side in a circle so that changes things. I mean lol at first I really thought it was going to be as easy as copying and pasting the same X Angles but changing the y rotation only. I made a draft Diagram to show what i try to explain (picture 1-cartesianMapping.png) is what I try to explain. The red lines show the 360 rotation on the X Axis with 11.5degree to - 11.5degree. when I go and try a 45 degree rotation i pretty much get the Blue circles as shown in the picture 1. It has to be it i guess... (note that the numbers in picture 1 used to draw the blue squares are just a draft-they are incorrect).

    But I got another problem... Which is in picture 2 (LATLONG1). A sphere like object with a Cartesian mapping projection has it's latitude and longitude that are kinda "bending". So that clearly shows that I can't use the same coordinates from top to bottom of the sphere projection to map my sprites. Every angles are going to be different from one another unless I Mirror the sprites with their negative Lat-Long counterparts but still I gotta map one side first to be able to do that. The thing is I am a perfectionist so I don't want to put any sort of data for those angles. I want it to be perfect if this project isn't a pure load of "im gonna get nowhere with this" lol.

    So I thought about using the primitive Sphere found on the Unity Wiki page and If I shoot the raycast from the camera to the transform of the parent of the skull sprite i can hit triangles of that sphere and catch the vertices that are making up those triangles that I hit... So with those vertices I also will have the "boundaries" of each latitude/longitude square. The sphere has its center point right where the parent of the skull is. Anyway that is another long shot by any means but if I get nowhere with just "blindly" mapping my sphere I will use that technique.

    If you wanna share your thoughts on this go right ahead. I Wonder if what I am trying here is even doable since there is no info on projecting a sprite on a 3d sphere for an ALL-around motion... I couldn't find nothing else than what you shared and every piece of info i can get my eyes on with StackOverflow and the unity Forums. I slightly searched for how to "billboard" a sprite in a 360 motion but again all the examples are about having a 360 motion on the Y Axis (latitude)... Anyway thanks for reading.
    Nine

    EDIT 20h37 eastern time - I might have really got the rotations right... check in on my ugly third picture cartesianMapping1.png. i just plugged the rotation in the inspector panel, hit play and rotated the Unify Wiki Sphere with my keyboard keys and logged the results on paper of every Lat/Lon that got debugged in console. Note that this might not be the final draft as I have enlarged the zones of each rotations "circle". Im gonna go test it.
     

    Attached Files:

    Last edited: Mar 12, 2017