Search Unity

Space Graphics Toolkit & Planets

Discussion in 'Assets and Asset Store' started by Darkcoder, Aug 18, 2012.

  1. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,241
    Not sure I understand. My camera is always very close to the top of the ring, so *some* part of the ring is always in view. And you're saying if any part of the ring is in view, the whole thing will go through the vertex buffer? If so, there doesn't seem to be anything I can do to improve performance except reduce the number of asteroids in the ring (which obviously reduces the realism of a dense ring).

    EDIT: Actually, in this screenshot, the camera is too high -- the inner flat-texture ring is not so obvious. The camera normally is never more than 3 meters up from the foreground ring.
     

    Attached Files:

  2. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    Wow, that's a lot of asteroids! Yeah, if the camera is always that close then there isn't much you can do to optimize it without writing a custom asteroid renderer, but that would be quite a lot of work, and doing so would require you to sacrifice certain orbital features.
     
  3. Marionette

    Marionette

    Joined:
    Feb 3, 2013
    Posts:
    349
    they're all clones right? shared meshes/textures? the only other thing you can do is check each against the frustrum and adjust in the vertex buffer.. unless there's a custom culling/lod component in unity that does that? sorry, i'm still coming up to speed with the editor and components myself.

    as a side note, there is always a point you come to, to balance between hardware capabilities and eye candy. welcome to that point ;)
     
  4. Xsnip3rX

    Xsnip3rX

    Joined:
    Aug 29, 2009
    Posts:
    197
    (In russian accent) Greetings my friend, how goes the progress?
     
  5. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    I'm still working on my next asset store product. Though some users did find some bugs with SGT that I've now fixed, these will be included in a new build soon, along with some new tutorial videos.
     
  6. Marionette

    Marionette

    Joined:
    Feb 3, 2013
    Posts:
    349
    WOOT!

    finally got the noise shader working. here's a small preview. still needs a lot of tweaks etc, but I think it came out pretty good. it's a start anyway ;)




    btw, I was thinking about a way to do a volumetric corona. or something that wouldn't feel so 'flat'. the coronas are nice and all, but they still 'feel' like billboards. it needs something in front of the star to give it a little 'depth'.. anything like that in the works Carlos?
     
    Last edited: Jul 17, 2013
  7. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    Excellent work, it certainly looks a lot better than static textures! Did you manage to get that all into Shader Model 2, or did you change it to 3?

    To make the corona planes look more volumetric you can tweak the fade ranges and plane counts so that it's a lot smoother than what you have right now. You could even layer multiple corona components to break up the similarities between each plane.

    I did have plans to create some form of coronal mass ejection effect previously, but I couldn't really think up a decent way to do it that wasn't just an animated billboard, or just a particle system. Both of these approaches would just rely on decent media, and there would be basically no programming to do, so I never added them.
     
  8. Marionette

    Marionette

    Joined:
    Feb 3, 2013
    Posts:
    349
    to be fair, since I didn't want to have to do the noise implementations myself, I purchased the turbulence library and Jereme was kind enough to provide the 4d implementations. all I did was implement it into SGT. because the noise is all on the GPU it's much faster but also meant that it uses 3.0 minimum. dx11 and 4.0 work as well. not sure if 2.0 could be achieved, but then i'm not a shader guru ;(

    the cool thing about the noise shader is that it not only will mix hi/lo colors but hi/lo textures and a turbulence texture as well.
     
  9. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    Yeah actual 4D noise is pretty intensive, so you'd probably have to use at least SM3. But you might be able to get a similar effect using pre-generated noise and some sort of scrolling colour look up table.
     
  10. VectorNector

    VectorNector

    Joined:
    May 22, 2013
    Posts:
    62
    Hey guys, would any know how to create textures for the nebula component? Does it have to formatted in a special way as a png? The pngs in the example work fine. I can't create one from PS if my life depended on it.
     
  11. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    The only special thing you have to do is make sure the edges of the texture are black. This is because the nebula particles use additive blending, so a non-black edge will give you an undesirable solid edge.

    The example nebula textures were created using the TimelineFX particle generator software, but you can probably produce similar ones with only photoshop easily enough. One method would be to create a fractal noise texture (Filter/Render/Clouds), then on a separate layer create a circular gradient where the inside is white and the outside is black, then blend them together using Multiply. You can then brush in some colours or details to make it more interesting.
     
  12. Marionette

    Marionette

    Joined:
    Feb 3, 2013
    Posts:
    349
    I have a question that maybe you might be able to help with.

    I have a star, and it's mass is say 10000. I have a planet, and it's mass is say 1000. I want the planet to orbit the star in a somewhat stable orbit, preferably circular, but elliptical will do as well. I need to be able to programmatically specify what amount of force that is needed to achieve the above orbit.

    more specifically, I need an algorithm to calculate this as a percentage of mass. I understand that distance, direction, drag etc all matter, but I just want to know if there's a calculation out there somewhere (preferably c#) that calculates the force needed to obtain a reasonable orbit given it's mass or mutual center of gravity or that I can use as reference.

    actually, my apologies. there isn't a simple quick answer..
     
    Last edited: Jul 18, 2013
  13. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    To have a circular orbit you want to use THIS equation. However, keep in mind that the SGT gravity components don't simulate Newtonian gravity, so these equations wouldn't work without modifying the gravity components.
     
  14. Azaphrael

    Azaphrael

    Joined:
    Nov 17, 2011
    Posts:
    41
    Just to chime in quickly, I'd have an item there on my wishlist:

    Cloud Shadows.

    Amazes me, that this hasn't come up yet.

    :grin:
     
  15. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    Clouds casting shadows on the planet surface? The fastest way would be to bake the cloud shadow into your planet texture (though obviously you then wouldn't be able to rotate the clouds), the only other methods I can think of would require the planet surface shader count to be doubled, which I don't want to do.

    In terms of shader code, the simplest method would be to just sample the equirectangular cloud texture using the surface UV, but offset the U based on the cloud rotation, though this wouldn't allow for long shadows near the edges of the light/dark side.

    If you just want your planet to look shadowed from a distance then you can also just add a drop-shadow to your cloud textures, I did that in an earlier build of SGT and it looked good.
     
  16. Azaphrael

    Azaphrael

    Joined:
    Nov 17, 2011
    Posts:
    41
    Amazes me why that hasn't come to my mind. :D

    Blisteringly fast answer, by the way. Thanks!
     
  17. ITIProd

    ITIProd

    Joined:
    Nov 18, 2012
    Posts:
    14
    Just purchased SGT. So far, I'm highly impressed! At this point, do you have any additional ideas/directions that you would like to realize in this package, or this basically the finished product? (just curious)
     
  18. Azaphrael

    Azaphrael

    Joined:
    Nov 17, 2011
    Posts:
    41
    Well, Darkcoder said that there will be a version 3.0 at some point. ;)
     
  19. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    In terms of core features I think it's pretty much complete, but there are some smaller things that I'd like to add. For example: an animated accretion disk/vortex like effect, comet trails, and some way to place images in the background easily.

    I also have some ideas about writing a more efficient Surface Tessellator component, along with procedural planet heights/textures, but I kind of doubt the time investment to write such components would be worth it. Maybe in the future I'll release a new package that includes lots of procedural stuff, as well as one with lots of spaceship-specific things.

    But right I'm only working on bug fixes for SGT, my next asset store product is maybe 80% complete, and I already have an idea for another one, so don't hold your breath for any of these features to come soon.
     
  20. Marionette

    Marionette

    Joined:
    Feb 3, 2013
    Posts:
    349
    hey Carlos? one thing I would like to suggest.

    Right now, all the code is kind of set to hide objects and the classes are a bit 'locked' in etc., not meaning that they can't be modified, just that some of the architecture is a bit constraining. Try to create everything programmatically and you'll see what I mean. The partial classes help etc, but there is only so far I can extend partial classes especially when some core functionality needs to be adjusted/changed, and when I update, it's starting to be a big undertaking. is there anything we might do, architecture-wise that might help resolve or ease that a little bit?
     
  21. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    Can you give me an example?

    You can disable the automatic hiding of GameObjects by commenting out line 2 of SpaceGraphicsToolkit/Required/Scripts/Library/SGT_Helper.cs

    I used partial classes because some of the core components were becoming massive, and it became hard to distinguish the message receivers from the actual class methods, and the field/property code was just hundreds of lines of the same thing so I just put them in separate files.
     
  22. doctor_wombat

    doctor_wombat

    Joined:
    Jul 14, 2013
    Posts:
    4
    Hi, I've recently purchased the SGT and it is brilliant, it has made my current project so much easier to handle and it looks great!

    I was wondering how to change the light source of a planet from in the script, as when I clone my planets they all still use the light source from the original planet.

    Thanks again, it's a great package!
     
  23. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    If your script has a reference to your planet and your other light source, for example:

    Code (csharp):
    1. public class YourComponent : MonoBehaviour
    2. {
    3.     public SGT_Planet      YourPlanet;
    4.     public SGT_LightSource YourLightSource;
    5.    
    6.     ...
    Then in Start/Awake/anywhere, you can just do:

    Code (csharp):
    1. YourPlanet.PlanetLightSource = YourLightSource;
     
  24. JayCrossler

    JayCrossler

    Joined:
    Jul 10, 2013
    Posts:
    10
    Love the kit. Just bought it and am really happy with it.

    Is there a description/example of how to access/programmatically create things from script? I didn't see any in the documentation, and saw lots of little pointers in the forums, but nothing definitive.

    For example, if I create a brand new scene and a new script (preferably Javascript), how would I add a planet then attach the orbiter script to it via code (via JavaScript)? I'd tried:
    Code (csharp):
    1.  
    2.             var orbitter:SGT_SimpleOrbit = planet.GetComponent(SGT_SimpleOrbit);
    3.             orbitter.OrbitPeriod = 20;
    4.  
    But wasn't able to import that object. Is the issue just that it can only be imported within C#? I've seen some forum posts that indicate that you need to change the build order between JS and C#... but all the links no longer work. Any suggestions?

    I'm aiming to build a solar system/objects fully programmatically. Thanks so much in advance!
     
    Last edited: Jul 26, 2013
  25. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    It seems that you just need to create a folder in your root assets directory called 'Plugins' and drag in SpaceGraphicsToolkit/Required/Scripts, and SpacegraphicsToolkit/Examples/Scripts. You should now be able to access all of SGT's functionality from js.

    If your GameObject only contains your custom script then you need to first call AddComponent(SGT_Planet); and AddComponent(SGT_SimpleOrbit); You can then set every variable as you would in the inspector, because most of the property names are identical.

    Let me know if you have any more issues/questions about this.
     
  26. doctor_wombat

    doctor_wombat

    Joined:
    Jul 14, 2013
    Posts:
    4
    That sorted it.

    Thanks for the help and the swift response! I'm looking forward to exploring what else this tool kit can achieve.
     
  27. newticus

    newticus

    Joined:
    Sep 4, 2012
    Posts:
    16
    Hi, I don't want to be a bother but I purchased this toolkit in hopes to make a small space exploration game. I have developed a double camera system so that planets that are "far" away are rendered smaller, but closer, and behind the main camera using the depth buffer. So many interesting things so far, and it works great! Thank you for this amazing product.

    Anyways, there is an issue I've stumbled upon now that I'm trying to "land" on a planet's surface. I added the Tessallator collider component and everything works great, but I can't seem to remove or disable the collider after the planet is added to the "distant" camera. So any colliders I currently have in the scene (mainly just the player's ship), will still collide with a massive invisible planet.

    How do you disable the tessallated collider in the code?

    So far I've tried these two, neither seem to work.
    Code (csharp):
    1. // _tess is a SGT_SurfaceTessellatorCollider, cached on Start
    2.             if(_tess.collider != null) _tess.collider.enabled = false;
    3.             _tess.enabled = false;
    Any help for a newbie?

    Edit: Found a quick fix, don't know if I really SHOULD be doing this, but I basically call the tessellator's OnDestroy function, tricking it into destroying all the collider meshes. The only problem I have with this, is regenerating the meshes when the planet is in range again isn't great for performance. I'd rather just disable the mesh and re-enable it, but that's what I don't know what to do.
     
    Last edited: Jul 28, 2013
  28. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    You're right, this is an oversight on my part. Open up SGT_SurfaceTessellatorCollider.cs and from line 104, replace the OnEnable and OnDisable methods with:

    Code (csharp):
    1. public void OnEnable()
    2.     {
    3.         StopAllCoroutines();
    4.        
    5.         if (Application.isPlaying == true)
    6.         {
    7.             StartCoroutine(Update_Coroutine());
    8.         }
    9.        
    10.         if (activeCollider != null)
    11.         {
    12.             activeCollider.MeshCollidersEnabled = true;
    13.             activeCollider.Update();
    14.         }
    15.     }
    16.    
    17.     public void OnDisable()
    18.     {
    19.         StopAllCoroutines();
    20.        
    21.         if (activeCollider != null)
    22.         {
    23.             activeCollider.MeshCollidersEnabled = false;
    24.             activeCollider.Update();
    25.         }
    26.     }
    You can now disable the collider by doing yourSurfaceTessellatorCollider.enabled = false;
     
  29. newticus

    newticus

    Joined:
    Sep 4, 2012
    Posts:
    16
    Awesome, thanks!
     
  30. Marionette

    Marionette

    Joined:
    Feb 3, 2013
    Posts:
    349
    are you doing that to get around the lack of precision on large areas? and if so, does it work?
     
  31. JayCrossler

    JayCrossler

    Joined:
    Jul 10, 2013
    Posts:
    10
    Thanks, this got me on the right track - though didn't exactly work for my case. I had already used both a number of SGT scripts and a number of custom scripts. After dragging the directory into plugins, I could now access the proper objects, but all of my existing links to SGT scripts broke. I had to recreate most of the scenes with the new locations. Also, I made some improper architecture decisions beforehand -- I'd used both .JS and .CS files trying to access each other, and sometimes it worked and sometimes not.

    This blog post helped a ton: http://www.41post.com/1935/programming/unity3d-js-cs-or-cs-js-access - basically every sub-directory within /plugins/ seems to get compiled independently, so putting the SGT in one subdir, the JS in another, and the C# in a third eventually solved everything.

    Anywho, next time I'll just use C# for everything.
     
  32. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    SGT is now 60% off in the madness sale! Grab it while you can!


    Great :)
     
  33. Uncasid

    Uncasid

    Joined:
    Oct 5, 2012
    Posts:
    193
    I am noticing a bug on the thrusters. I am building the roll portion. I notice that the thruster controller grabs port / starboard correctly, but it also grabs for / aft. It needs to detect for / aft based on center forward (ie, forward / rear of center of mass within a margin should be ignored)

    I would also like to see a way to set the objects center of mass on the SGT_3DSpaceshipController :) I am adding it myself right now
     
    Last edited: Aug 2, 2013
  34. Uncasid

    Uncasid

    Joined:
    Oct 5, 2012
    Posts:
    193
    wow, ok.. Adding it to the thruster controller was a no go. Serialization wouldn't work with the vector3. I can't figure out why.
     
  35. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    Yeah the component's a bit basic right now. When I have some free time I'll play around with it and see if it's something that can easily be improved.

    I originally wanted the component to more accurately do burns based on your desired direction or axis, because right now you'll notice that if your thruster setup isn't balanced then it's quite easily for a simple 'move forward' order to cause your ship to roll, or move off axis. However, after doing a bit of research it seems the maths requires for that is way above my level.

    If you make any progress with the spaceship components then I'd love to see what you come up with :)


    Should work. If you made the variable private are you sure you marked it with: [SerializeField] ?
     
    Last edited: Aug 2, 2013
  36. Uncasid

    Uncasid

    Joined:
    Oct 5, 2012
    Posts:
    193
    This is what I did and where I did it:

    SGT_ThrusterController.cs @ Line 12
    Code (csharp):
    1.  
    2.     [SerializeField]
    3.     private Vector3 centerOfMass;
    4.    
    5.     public Vector3 CenterOfMass {
    6.         get { return centerOfMass; }
    7.         set { centerOfMass = value; this.rigidbody.centerOfMass = value; }
    8.     }
    9.  
    SGT_Inspector_ThrusterController.cs @ line 13
    Code (csharp):
    1.  
    2.         SGT_EditorGUI.BeginGroup("Center Of Mass");
    3.         {
    4.            
    5.             ((SGT_ThrusterController)Target).CenterOfMass = EditorGUILayout.Vector3Field("Center of Mass", ((SGT_ThrusterController)Target).CenterOfMass);
    6.            
    7.         }
    8.         SGT_EditorGUI.EndGroup();
    9.  
    I have this to tell me where the center of mass is (changes based on the field above)
    Code (csharp):
    1.  
    2. using UnityEditor;
    3. using UnityEngine;
    4.  
    5. [CustomEditor(typeof(Rigidbody))]
    6. public class SOV_RigidBodyDraw : Editor {
    7.  
    8.     void OnSceneGUI()
    9.     {
    10.         Rigidbody rb = target as Rigidbody;
    11.         Handles.color = Color.red;
    12.         Handles.SphereCap(1, rb.transform.TransformPoint(rb.centerOfMass), rb.rotation, 1f);
    13.     }
    14.    
    15.     public override void OnInspectorGUI()
    16.     {
    17.         GUI.skin = EditorGUIUtility.GetBuiltinSkin(UnityEditor.EditorSkin.Inspector);
    18.         DrawDefaultInspector();
    19.     }
    20.  
    21. }
    22.  
    It all works fine and dandy in editor, but as soon as I run the script; The vector 3 is zeroed. This state continues back to the scene manager. I can get the serialization working just fine with my other classes, so I am not sure if you have something changing how it operates on the backend or not.
     
  37. Uncasid

    Uncasid

    Joined:
    Oct 5, 2012
    Posts:
    193
    It appears I just fixed it... Didn't take into account Garbage Collection :|

    Here is the class for those that want it.

    SGT_ThrusterController
    Code (csharp):
    1. using ThrusterList = System.Collections.Generic.List<SGT_Thruster>;
    2.  
    3. using UnityEngine;
    4.  
    5. [AddComponentMenu("Space Graphics Toolkit/Thruster Controller")]
    6. public partial class SGT_ThrusterController : SGT_MonoBehaviourUnique<SGT_ThrusterController>
    7. {
    8.     [SerializeField]
    9.     private ThrusterList thrusters;
    10.    
    11.     [SerializeField]
    12.     private Vector3 centerOfMass;
    13.    
    14.     public Vector3 CenterOfMass {
    15.         get { return centerOfMass; }
    16.         set { centerOfMass = new Vector3(value.x, value.y, value.z); this.rigidbody.centerOfMass = new Vector3(value.x, value.y, value.z); }
    17.     }
    18.    
    19.     public int ThrusterCount
    20.     {
    21.         get
    22.         {
    23.             return thrusters != null ? thrusters.Count : 0;
    24.         }
    25.     }
    26.    
    27.     public void FindAllThrustersInChildren()
    28.     {
    29.         thrusters = new ThrusterList(GetComponentsInChildren<SGT_Thruster>());
    30.     }
    31.    
    32.     public void AddThruster(SGT_Thruster thruster)
    33.     {
    34.         if (thrusters == null) thrusters = new ThrusterList();
    35.        
    36.         thrusters.Add(thruster);
    37.     }
    38.    
    39.     public SGT_Thruster GetThruster(int index)
    40.     {
    41.         return SGT_ArrayHelper.Index(thrusters, index);
    42.     }
    43.    
    44.     public void RemoveThruster(int index)
    45.     {
    46.         SGT_ArrayHelper.Remove(thrusters, index);
    47.     }
    48.    
    49.     public void RemoveThruster(SGT_Thruster thruster)
    50.     {
    51.         SGT_ArrayHelper.Remove(thrusters, thruster);
    52.     }
    53.    
    54.     public void ResetAllThrusters()
    55.     {
    56.         if (thrusters != null)
    57.         {
    58.             foreach (var thruster in thrusters)
    59.             {
    60.                 thruster.ThrusterThrottle = 0.0f;
    61.             }
    62.         }
    63.     }
    64.    
    65.     public void ThrusterBurn(float throttle)
    66.     {
    67.         if (thrusters != null)
    68.         {
    69.             foreach (var thruster in thrusters)
    70.             {
    71.                 thruster.ThrusterThrottle += throttle;
    72.             }
    73.         }
    74.     }
    75.    
    76.     public void ThrusterLinearBurn(Vector3 direction, float throttle, Space space)
    77.     {
    78.        
    79.         if (thrusters != null)
    80.         {
    81.             if (throttle < 0)
    82.             {
    83.                 direction = -direction;
    84.                 throttle  = -throttle;
    85.             }
    86.            
    87.             if (space == Space.Self)
    88.             {
    89.                 direction = transform.localRotation * direction;
    90.             }
    91.            
    92.             foreach (var thruster in thrusters)
    93.             {
    94.                 if (Vector3.Dot(thruster.transform.forward, direction) < -0.9f)
    95.                 {
    96.                     thruster.ThrusterThrottle += throttle;
    97.                 }
    98.             }
    99.         }
    100.     }
    101.    
    102.     public void ThrusterAngularBurn(Vector3 axis, float throttle, Space space)
    103.     {
    104.         if (thrusters != null)
    105.         {
    106.             if (throttle < 0)
    107.             {
    108.                 axis     = -axis;
    109.                 throttle = -throttle;
    110.             }
    111.            
    112.             if (space == Space.Self)
    113.             {
    114.                 axis = transform.rotation * axis;
    115.             }
    116.            
    117.             foreach (var thruster in thrusters)
    118.             {
    119.                
    120.                 // Make sure the thruster is on port / starboard
    121.                
    122.                 var force        = thruster.transform.forward;
    123.                 var centre       = SGT_Helper.ClosestPointToLineB(rigidbody.worldCenterOfMass, axis, thruster.transform.position);
    124.                 var displacement = thruster.transform.position - centre;
    125.                 var torque       = Vector3.Cross(displacement, force);
    126.                
    127.                 if (Mathf.Abs(Vector3.Dot(displacement.normalized, force)) < 0.9f)
    128.                 {
    129.                     if (Vector3.Dot(torque.normalized, axis) < -0.9f)
    130.                     {
    131.                         print ("Thruster: " + thruster.name + ", math: " + (Vector3.Dot(torque.normalized, axis)));
    132.                         thruster.ThrusterThrottle += throttle;
    133.                     }
    134.                 }
    135.             }
    136.         }
    137.     }
    138. }
    139.  
    SGT_Inspector_ThrusterController

    Code (csharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3.  
    4. [CustomEditor(typeof(SGT_ThrusterController))]
    5. [CanEditMultipleObjects]
    6. public class SGT_Inspector_ThrusterController : SGT_Inspector<SGT_ThrusterController>
    7. {
    8.     public override void OnInspector()
    9.     {
    10.        
    11.         SGT_EditorGUI.Separator();
    12.        
    13.         SGT_EditorGUI.BeginGroup("Center Of Mass");
    14.         {
    15.            
    16.             ((SGT_ThrusterController)Target).CenterOfMass = EditorGUILayout.Vector3Field("Center of Mass", ((SGT_ThrusterController)Target).CenterOfMass);
    17.            
    18.         }
    19.         SGT_EditorGUI.EndGroup();
    20.        
    21.         SGT_EditorGUI.BeginGroup("Thrusters");
    22.         {
    23.             SGT_EditorGUI.BeginIndent(Target.ThrusterCount > 0, 1);
    24.             {
    25.                 for (var i = 0; i < Target.ThrusterCount; i++)
    26.                 {
    27.                     var rect = SGT_EditorGUI.Reserve();
    28.                     bool pressed; SGT_EditorGUI.DrawEditableObjectWithButton(rect, Target.GetThruster(i), "X", out pressed, 25.0f, true);
    29.                    
    30.                     if (pressed == true)
    31.                     {
    32.                         Target.RemoveThruster(i);
    33.                     }
    34.                 }
    35.             }
    36.             SGT_EditorGUI.EndIndent();
    37.            
    38.             SGT_EditorGUI.Separator(Target.ThrusterCount > 0);
    39.            
    40.             var newThruster = SGT_EditorGUI.ObjectField<SGT_Thruster>("Add Thruster", null, null, false);
    41.            
    42.             if (newThruster != null)
    43.             {
    44.                 Target.AddThruster(newThruster);
    45.             }
    46.            
    47.             SGT_EditorGUI.Separator();
    48.            
    49.             if (SGT_EditorGUI.Button("Find In Children") == true)
    50.             {
    51.                 SGT_EditorGUI.MarkModified(true, true);
    52.                
    53.                 Target.FindAllThrustersInChildren();
    54.             }
    55.            
    56.             if (SGT_EditorGUI.Button("Min Throttle") == true)
    57.             {
    58.                 SGT_EditorGUI.MarkModified(true, true);
    59.                
    60.                 Target.ResetAllThrusters();
    61.             }
    62.            
    63.             if (SGT_EditorGUI.Button("Max Throttle") == true)
    64.             {
    65.                 SGT_EditorGUI.MarkModified(true, true);
    66.                
    67.                 Target.ThrusterBurn(1.0f);
    68.             }
    69.         }
    70.         SGT_EditorGUI.EndGroup();
    71.        
    72.         SGT_EditorGUI.Separator();
    73.     }
    74.    
    75. }
     
    Last edited: Aug 2, 2013
  38. Uncasid

    Uncasid

    Joined:
    Oct 5, 2012
    Posts:
    193
    You could trick it! Giving the user the ability to change the center of mass is a step in the right direction. All you need to do is make sure that the center of the force is in line with the center of mass.

    Or, just use forces on the ridgidbody only. Use the thrusters as show?
     
    Last edited: Aug 2, 2013
  39. JayCrossler

    JayCrossler

    Joined:
    Jul 10, 2013
    Posts:
    10
    Can you assist in helping me script the star "SurfaceMesh"? For example, is there a way to declare a SurfaceMesh and SurfaceTexture below from code? I'l like to be able to pass in the texture name to build the object. Using the below code, I'm faking it by trying to set it equal to an existing object, which still doesn't work well. Any suggestion?

    Code (csharp):
    1.  
    2.         GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
    3.         sphere.transform.position = location;
    4.  
    5.         //Add Star data
    6.         SGT_Star sStar = (SGT_Star) sphere.AddComponent(typeof(SGT_Star));
    7.  
    8.         //NOTE: Temporary way to try to set component data:        
    9.         GameObject temp = GameObject.Find("Small Star");
    10.         SGT_Star temp2 = (SGT_Star)temp.GetComponent("SGT_Star");
    11.        
    12.         sStar.SurfaceMesh = temp2.SurfaceMesh;
    13.         sStar.SurfaceTexture = temp2.SurfaceTexture;
    14.         sStar.AtmosphereMesh = temp2.AtmosphereMesh;
    15.         sStar.SurfaceRadius = 3;
    16.         sStar.AtmosphereFog = 0.18f;
    17.         sStar.AtmosphereFalloffSurface = 2.68f;
    18.         sStar.AtmosphereFalloffInside = 0f;
    19.         sStar.AtmosphereFalloffOutside = 3f;
    20.         sStar.AtmosphereHeight = 1;
    21.         sStar.SurfaceCollider = true;
    22.                
    23.        
    24.         //Add Gravity data
    25.         SGT_GravitySource sGravS = (SGT_GravitySource) sphere.AddComponent(typeof(SGT_GravitySource));
    26.         sGravS.GravitySourceType = SGT_GravitySource.GravityType.Exponential;
    27.         sGravS.GravitySourceForce = 800;
    28.         sGravS.GravitySourceHeight = 1000;
    29.         sGravS.GravitySourceRadius = 0;
    30.  
    31.         SGT_GravityReceiver sGravR = (SGT_GravityReceiver) sphere.AddComponent(typeof(SGT_GravityReceiver));
    32.         sGravR.Type = SGT_GravityReceiver.GravityType.Multiple;
    33.        
    34.         //Add Rigidbody physics
    35.         Rigidbody sRigid = (Rigidbody) sphere.AddComponent(typeof(Rigidbody));
    36.         sRigid.mass = 10;
    37.         sRigid.drag = 0;
    38.         sRigid.angularDrag = 0.05f;
    39.         sRigid.useGravity = false;
    40.  
     
  40. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    Could do, but then it wouldn't be Newtonian. You can already change the force mode to ignore the thruster location, but that wouldn't work for rolling. In any case, the spaceship control scripts are just designed for very basic prototyping, I doubt you want to use anything that basic in an actual game.

    As for your Vector3 issue, I don't see how your changes would make any difference. Vector3 is a struct, so there should be no difference between assigning that to the two fields and creating new Vector3s before assigning.


    You can't copy the data cross like that because the set accessors are empty, I don't exactly remember the reason why I did this for those particular properties, but I'm sure there was some good reason. If you open up SGT_Star_Properties.cs and go to lines 103 117, you can fill in the set accessors and see if it works. The code would be "surfaceMultiMesh = value;" and "surfaceTexture = value;" respectively.

    If it doesn't work for some reason then you'll probably have to manually copy all the fields across, but looking at the code it looks like it might work ok?

    If you just want to assign the meshes and textures from code then look at SGT_ProceduralStarSystem.cs lines 177-178. Although that code is for setting up a planet, the code for setting up a star should look almost the same.
     
    Last edited: Aug 3, 2013
  41. JayCrossler

    JayCrossler

    Joined:
    Jul 10, 2013
    Posts:
    10
    Perfect, you rock. That file has everything I need.
     
  42. Uncasid

    Uncasid

    Joined:
    Oct 5, 2012
    Posts:
    193
    You are right, it does the trick for me :)

    Try it out for yourself.. it is very weird how it was acting.
     
  43. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    I just tried it, and it works fine for me. Maybe you modified it in play mode? Or maybe you put it in a prefab and it got copied over or something?

    Also, with code like that I would probably set the centreOfMass value in Update, because the rigidbody is externally subject to change, so the value could change.
     
  44. OhiraKyou

    OhiraKyou

    Joined:
    Mar 27, 2012
    Posts:
    259
    Everything seems to require an observer camera. However, split screen (multiple camera) multiplayer is a big part of my game. Exactly what can and can't this do in split screen?
     
  45. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    Most of the components require you to set a camera because certain calculations require the camera's position to produce the final result. A good example is the planet atmosphere, the camera's location is used to test if you're inside or outside the atmosphere, because different shaders must be used depending on which side you're on.

    If the cameras in your scene are always relatively close together then you can probably get away with setting either of them in the components that require cameras. However, if they can be relatively far away from each other then it's very likely your scene will begin to look incorrect in one of your views (you can already test this by moving the scene view camera around without moving the game view camera). Unfortunately, outside of a camera script I don't believe there's a way to detect when an object is about to be rendered, so I didn't add support for automatically switching shaders to a different view.

    Without any additional code, the easiest way to fix this issue is to duplicate the SGT objects so there's one for each camera view, then you change the layer and camera culling masks to only render the required one. But this method would have quite a bit of overhead.

    A better approach would be to write a camera script that stores every applicable component in a list, and when 'OnPreRender' is called, you'd loop through all the components and set their Observer field to the current camera and call LateUpdate, which should automatically update all the camera calculations.
     
  46. OhiraKyou

    OhiraKyou

    Joined:
    Mar 27, 2012
    Posts:
    259
    Thanks. It's a neat system, but I'll pass for now. Perhaps I'll come back to it when I get back to single player projects.
     
  47. Simie

    Simie

    Joined:
    Oct 26, 2012
    Posts:
    456
    Just bought this in the madness sale, it's been amazing so far. It's made my game look much more professional, thanks!

    I can't see the misty galaxy demo in the package, is that available anywhere? I'd like to see how it's done.
     
  48. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    I believe the reason why I didn't include that demo into the official SGT release is because I couldn't find a good source of galaxy images with licenses that allowed me to publish them on the asset store. For example, if an image is 'free' but the license stipulates that you can't sell the image as part of some pack, then I can't include it in SGT. But depending on the license I might be able to use that same image in a promotional demo where the image files themselves aren't freely available as-is.

    Because of this, I'm pretty much limited to making/buying my own media, or using public domain sources. However, there are tons of great sources out there that only require attribution which most people should be able to provide in their own projects without issue.
     
    Last edited: Aug 6, 2013
  49. Simie

    Simie

    Joined:
    Oct 26, 2012
    Posts:
    456
    Could you describe which components you used to create that scene then? I'm fine with finding my own source materials, I'd just like to know what I need.

    Thanks
     
  50. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    For the galaxy I layered a single nebula with a single starfield using similar settings to the 'Elliptical Galaxy' demo scene. The source galaxy image was of a barred spiral galaxy, probably with the contrast boosted a lot. The background was just a dust field with one of the packaged green particles, and a starfield, I believe I just copied it from one of the other demo scenes.