Space Game Starter Kit [Released]

Discussion in 'Assets and Asset Store' started by ArenMook, Oct 11, 2011.

  1. Thinker

    Thinker

    Member

    Joined:
    Oct 4, 2010
    Messages:
    409
    ArenMook are you plaining in future to update this Kit in any way ? :)
    Or is it complitly finished and you will leav it as it is ?
  2. ArenMook

    ArenMook

    Member

    Joined:
    Oct 20, 2010
    Messages:
    1,901
    There are some things I'd like to add to it still, but lately NGUI has been swallowing all of my dev time and then some. :|
  3. Thinker

    Thinker

    Member

    Joined:
    Oct 4, 2010
    Messages:
    409
    I understand that completely :) just can you adjust the flight control settings ? Like i ask in post long time ago :D. its at the begging of page number 10.

    :)
  4. ArenMook

    ArenMook

    Member

    Joined:
    Oct 20, 2010
    Messages:
    1,901
    Sure, I'll add it to the NGUI's list. That way I'll get to it as I keep at it. :)
  5. Rajmahal

    Rajmahal

    Member

    Joined:
    Apr 20, 2011
    Messages:
    764
    Hi Arenmook,

    One thing I would love to see in this package would be the ability to add gravity to a space object. For example, if you could add gravity to the planet and have it pull objects towards its central point, that would then allow for objects (such as the space ship) to get into orbit with it and such.

    Would this be difficult to add or is it a lot more complicated than it sounds? I noticed that the space station has a form of gravity in its sphere which pulls the ship directly downwards when it enters it. Could this be modified to pull the ship towards the centre of the sphere instead?
  6. ArenMook

    ArenMook

    Member

    Joined:
    Oct 20, 2010
    Messages:
    1,901
    The planet is a distant object that the ship shouldn't be able to get too close to. You can certainly modify it to make it pull the ship, but establishing orbit around it would be a lot more difficult than you might think. For starters, you will have to be travelling really quickly around the planet -- much faster than the ship can currently move.
  7. Rajmahal

    Rajmahal

    Member

    Joined:
    Apr 20, 2011
    Messages:
    764
    I'm thinking of doing a racing space game where racers use gravity of asteroids and perhaps some super dense objects to get into an orbit, make a sharp bend and then rocket off to the next checkpoint. If I wanted to do this, would the best bet be to try and modify the gravity script in the space station sphere to change the force from pulling down on the y axis to pulling towards the centre of the sphere?
  8. ArenMook

    ArenMook

    Member

    Joined:
    Oct 20, 2010
    Messages:
    1,901
  9. Nicotine67

    Nicotine67

    New Member

    Joined:
    Jun 26, 2011
    Messages:
    11
    Hi ArenMook,

    I purchased SGSK last night, and just wanted to introduce myself.

    I don't have a lot of money to spend on asset bundles (I'm a new dad of 2 babies ;) ), but I couldn't come up with any good reasons to not get this kit. There's some really great ideas in here! I also really appreciate that you're responsive to the community and I look forward to interacting with you guys. :cool:


    Guitboxgeek
  10. ArenMook

    ArenMook

    Member

    Joined:
    Oct 20, 2010
    Messages:
    1,901
    There is no "you guys", just me. :p
  11. Thinker

    Thinker

    Member

    Joined:
    Oct 4, 2010
    Messages:
    409
    ArenMook i wonder if you will add the Radar that you were talking about some time ago :).
  12. ArenMook

    ArenMook

    Member

    Joined:
    Oct 20, 2010
    Messages:
    1,901
    You know I want to. Problem is time... :|
  13. Thinker

    Thinker

    Member

    Joined:
    Oct 4, 2010
    Messages:
    409
    That time can be such an ass sometimes :|
  14. Crazy Robot

    Crazy Robot

    Member

    Joined:
    Apr 18, 2009
    Messages:
    931
    I implemented the Radar solution from the Wiki! It works well with some tweaking. I have it running on the iPhone 3Gs with no performance hit. I just had to optimize it and remove the OnGUI in it. If you're building for the Mac or PC it would be even easier. I tweaked it to show a radar screen in the upper left corner, if you tap on the radar screen, it will change range for you. (600, 1500, and 5000).
  15. S0ULART

    S0ULART

    Member

    Joined:
    Jun 14, 2011
    Messages:
    121
    @Crazy Robot:
    Would you mind to maybe share your implementation?
  16. Crazy Robot

    Crazy Robot

    Member

    Joined:
    Apr 18, 2009
    Messages:
    931
    Sure. I'm not at my desk right now, but I will post what I have later.
  17. Crazy Robot

    Crazy Robot

    Member

    Joined:
    Apr 18, 2009
    Messages:
    931
    Ok so here is the radar script itself from the Wiki (it's not the entire project so you will want to get it from the wiki to get all the other stuff, all I did was add the screen resolution All this really does is add a GUI dot on the scope. I set it to custom and the enemy tag as "Enemy". See lower for more. Keep in mind, I am not a programmer, so some of the code may be dirty!! Also, this is not my full code, just parts of the scripts, so you can use this to get the idea. But the bottom two lack all a lot of the vars.

    Code (csharp):
    1. @script ExecuteInEditMode()
    2. // radar! by PsychicParrot, adapted from a Blitz3d script found in the public domain online somewhere ..
    3.  
    4. //Modified by Dastardly Banana to add radar size configuration, different colors for enemies in different states (patrolling or chasing), ability to move radar to either one of 9 preset locations or to custom location.
    5.  
    6. //some lines are particular to our AI script, you will need to change "EnemyAINew" to the name of your AI script, and change "isChasing" to the boolean within that AI script that is true when the enemy is active/can see the player/is chasing the player.
    7.  
    8. var blip : Texture; // texture to use when the enemy isn't chasing
    9. var blipChasing : Texture; //When Chasing
    10. //var radarBG : Texture;
    11.  
    12. var centerObject : Transform;
    13. var mapScale = 0.3;
    14. var mapSizePercent = 15;
    15.  
    16. var checkAIscript : boolean = true;
    17. var enemyTag = "Enemy";
    18.  
    19. enum radarLocationValues {topLeft, topCenter, topRight, middleLeft, middleCenter, middleRight, bottomLeft, bottomCenter, bottomRight, custom}
    20. var radarLocation : radarLocationValues = radarLocationValues.bottomLeft;
    21.  
    22. private var mapWidth : float;
    23. private var mapHeight : float;
    24. private var mapCenter : Vector2;
    25. private var mapCenterCustom : Vector2;
    26.  
    27.  
    28.  function Awake (){
    29.  if (Screen.width == 480)
    30.  mapCenterCustom = Vector2(73*.5, 160*.5);
    31.  else
    32.  if (Screen.width == 1024){
    33.  mapCenterCustom = Vector2(58, 170);
    34.  mapSizePercent = 8;
    35.  }
    36.  else{
    37.  mapCenterCustom = Vector2(73, 160);
    38.  mapSizePercent = 12;
    39.          }
    40.  }
    41.  
    42. function Start () {
    43.     setMapLocation();  
    44. }
    45.  
    46.  
    47. function OnGUI () {
    48. //  GUI.matrix = Matrix4x4.TRS (Vector3.zero, Quaternion.identity, Vector3(Screen.width / 600.0, Screen.height / 450.0, 1));
    49.  
    50.     // Draw player blip (centerObject)
    51. var     bX=centerObject.transform.position.x * mapScale;
    52. var     bY=centerObject.transform.position.z * mapScale;   
    53.     //GUI.DrawTexture(Rect(mapCenter.x - mapWidth/2,mapCenter.y-mapHeight/2,mapWidth,mapHeight),radarBG);
    54.    
    55.     // Draw blips for Enemies
    56.     DrawBlipsForEnemies();
    57.    
    58. }
    59.  
    60. function drawBlip(go : GameObject,aTexture){
    61.    
    62. var centerPos=centerObject.position;
    63. var extPos=go.transform.position;
    64.    
    65.     // first we need to get the distance of the enemy from the player
    66. var dist=Vector3.Distance(centerPos,extPos);
    67.      
    68. var dx=centerPos.x-extPos.x; // how far to the side of the player is the enemy?
    69. var dz=centerPos.z-extPos.z; // how far in front or behind the player is the enemy?
    70.    
    71.     // what's the angle to turn to face the enemy - compensating for the player's turning?
    72. var deltay=Mathf.Atan2(dx,dz)*Mathf.Rad2Deg - 270 - centerObject.eulerAngles.y;
    73.    
    74.     // just basic trigonometry to find the point x,y (enemy's location) given the angle deltay
    75. var bX=dist*Mathf.Cos(deltay * Mathf.Deg2Rad);
    76. var bY=dist*Mathf.Sin(deltay * Mathf.Deg2Rad);
    77.    
    78.     bX=bX*mapScale; // scales down the x-coordinate so that the plot stays within our radar
    79.     bY=bY*mapScale; // scales down the y-coordinate so that the plot stays within our radar
    80.    
    81.     if(dist<=mapWidth*.5/mapScale){
    82.         // this is the diameter of our largest radar circle
    83.        GUI.DrawTexture(Rect(mapCenter.x+bX,mapCenter.y+bY,3,3),aTexture);
    84.  
    85.     }
    86.  
    87. }
    88.  
    89. function DrawBlipsForEnemies(){
    90.     //You will need to replace isChasing with a variable from your AI script that is true when              the enemy is chasing the player, or doing watever you want it to be doing when it is red on             the radar.
    91.    
    92.     //You will need to replace "EnemyAINew with the name of your AI script
    93.    
    94.     // Find all game objects tagged Enemy
    95.     var gos : GameObject[];
    96.     gos = GameObject.FindGameObjectsWithTag(enemyTag);
    97.  
    98.     var distance = Mathf.Infinity;
    99.     var position = transform.position;
    100.  
    101.     // Iterate through them and call drawBlip function
    102.     for (var go : GameObject in gos)  {
    103.             var blipChoice : Texture = blip;
    104.             if(checkAIscript){
    105.                 var aiScript : EnemyAI = go.GetComponent("EnemyAI");
    106.             if(aiScript.isChasing)
    107.                     blipChoice = blipChasing;
    108.         }
    109.         drawBlip(go,blipChoice);
    110.     }
    111.  
    112. }
    113.  
    114. function setMapLocation () {
    115.     mapWidth = Screen.width*mapSizePercent/100.0;
    116.     mapHeight = mapWidth;
    117.  
    118.         mapCenter = mapCenterCustom;
    119.  
    120.    
    121. }
    Now here is scope code. I use EZGUI to make the scope texture and button to select the range. So all I do is have a button on the scope texture that when tapped sends a call to "MapRngChg", then that will send a call to the Radar Script above to change the map scale (range). This is for iOS so you will see the Screensize stuff to change where things are on the screen depending on what the resolution is.

    Code (csharp):
    1.  
    2.  
    3. if (Screen.width == 480){
    4. screensize = 0;
    5. radar.mapScale = 0.2;
    6.  
    7. }
    8. else
    9.  
    10. if (Screen.width == 1024){
    11. screensize = 1;
    12. GUIMenu.localScale -= Vector3(0.5,0.5,0);
    13. GUIMenu.localPosition = Vector3(-2.055313,1.455046,2.867615);
    14. radarMap.localScale -= Vector3(0.4,0.4,0);
    15. radarMap.localPosition = Vector3(-1.995972,0.9417305,2.867599);
    16. }
    17.  
    18. else
    19. {
    20. screensize = 2;
    21. radar.mapScale = 0.3;
    22. }
    23.  
    24.  
    25. function MapRngChg () {
    26.  
    27. if (CurrRange == 0){
    28.  
    29. if (screensize == 2)
    30. radar.mapScale = 0.2;
    31.  
    32. if (screensize == 1)
    33. radar.mapScale = 0.2;
    34.  
    35. if (screensize == 0)
    36. radar.mapScale = 0.1;
    37.  
    38. MapRangeText.Text =  ("1400");
    39. CurrRange = 1;
    40. return;
    41. }
    42. if (CurrRange == 1){
    43.  
    44. if (screensize == 2)
    45. radar.mapScale = 0.08;
    46.  
    47. if (screensize == 1)
    48. radar.mapScale = 0.05;
    49.  
    50. if (screensize == 0)
    51. radar.mapScale = 0.04;
    52.  
    53. MapRangeText.Text =  ("5000");
    54. CurrRange = 2;
    55. return;
    56. }
    57. if (CurrRange == 2){
    58.  
    59. if (screensize == 2)
    60. radar.mapScale = 0.3;
    61.  
    62. if (screensize == 1)
    63. radar.mapScale = 0.3;
    64.  
    65. if (screensize == 0)
    66. radar.mapScale = 0.2;
    67.  
    68.  
    69. MapRangeText.Text =  ("600");
    70. CurrRange = 0;
    71. return;
    72. }
    73. }
    What I found is it's still difficult to tell where the enemy is in 3D this radar works well with 2D, but still ok enough to tell you were everyone is and how many are out there. So What I did was add a tag that shows up above the closets enemy to you and will remain on the screen even if the enemy is off screen. the tag will follow the closest enemy at the edge of the screen. This uses a on OnGUI, but the game still runs at a solid 30 FPM on my 3Gs.

    Code (csharp):
    1.  
    2. var GuiText : GUIText;
    3.  
    4. InvokeRepeating ("CompassGo", .5, .1);
    5.  
    6. function CompassGo () {
    7.  
    8.  
    9.  
    10.  
    11. var ClosetsEnemy = GetNearestEnemyTaggedObject ();
    12.     if (ClosetsEnemy == null){
    13.     EnemyCont.gameObject.active = false;
    14.       CancelInvoke ("CompassGo");
    15.    
    16.     return;
    17.     }
    18.     else
    19.     EnemyCont.gameObject.active = true;
    20. EnemyCont.target = ClosetsEnemy.transform;
    21.            
    22.    
    23.            
    24.  }
    25.  
    26. function GetNearestEnemyTaggedObject() : Transform {
    27.     // and finally the actual process for finding the nearest object:
    28.  
    29.     var nearestDistanceSqr = Mathf.Infinity;
    30.     var taggedGameObjects = GameObject.FindGameObjectsWithTag("Enemy");
    31.    
    32.     var nearestObj : Transform = null;
    33.  
    34.     // loop through each tagged object, remembering nearest one found
    35.     for (var obj : GameObject in taggedGameObjects) {
    36.  
    37.         var objectPos = obj.transform.position;
    38.         var distanceSqr = (objectPos - player.position).sqrMagnitude;
    39.  
    40.         if (distanceSqr < nearestDistanceSqr) {
    41.             nearestObj = obj.transform;
    42.             nearestDistanceSqr = distanceSqr;
    43.         }
    44.        
    45.         var dis = nearestDistanceSqr * .01;
    46.         var temp : int = (dis - 3);
    47.        
    48.             dis = (temp / 5) * 5;
    49.         GuiText.text = "" + dis;
    50.        
    51.     }
    52.  
    53.     return nearestObj;
    54. }
    55.  
  18. mente

    mente

    New Member

    Joined:
    Nov 10, 2011
    Messages:
    10
    Can I use your extension for 2D scroller game?
  19. ArenMook

    ArenMook

    Member

    Joined:
    Oct 20, 2010
    Messages:
    1,901
    Is this a question for SGSK or the radar system posted above?
  20. mente

    mente

    New Member

    Joined:
    Nov 10, 2011
    Messages:
    10
    ArenMook, for SGSK
  21. pqumsieh

    pqumsieh

    New Member

    Joined:
    Feb 28, 2012
    Messages:
    7
    Hey ArenMook,

    Looks like Unity 3.5 moves the project settings from Library to a folder titled "Project Settings". Might be helpful to update the readme file to indicate this change for future users.

    I am also noticing an error with Unity 3.5. I am getting an "Invalid SceneHandle" error. It states:

    Error in file: C:/BuildAgent/work/b0bcff80449a48aa/Runtime/Camera/UnityScene.cpp at line: 283

    Could you shed some light on this error. It seems to go away once you run the game, but reappears when you go back into the editor.
  22. ArenMook

    ArenMook

    Member

    Joined:
    Oct 20, 2010
    Messages:
    1,901
    @mente: It would be a completely different style of a game. I can maybe see you starting with the arcade example and changing the camera so it's looking at the side of the ship, but to be honest with you I'm not sure how helpful this starter kit would be for you as a 2D scroller game would be a completely different game in its scope.

    @pqumsieh: I've noticed odd issues with 3.5 that are completely on the Unity's side. I've submitted a bug about it a few weeks ago and haven't heard back from them. The error you're getting is inside Unity's C++ source code.
    Last edited: Feb 29, 2012
  23. pqumsieh

    pqumsieh

    New Member

    Joined:
    Feb 28, 2012
    Messages:
    7
    Hey Aren,

    One more question, I was running the profiler taking a look at resource usage and I noticed 90% of resources were being used by something titled "WaitforTargetFPS".

    I tried to figure out what this was doing and where it was located but I had no success. Could you possibly shed some light on this for me please?

    Cheers,
    Peter
  24. ArenMook

    ArenMook

    Member

    Joined:
    Oct 20, 2010
    Messages:
    1,901
    That simply means that the framerate is a lot higher than 60 FPS, and it's capped at 60 due to V-Sync. Another Unity thing.
  25. pqumsieh

    pqumsieh

    New Member

    Joined:
    Feb 28, 2012
    Messages:
    7
    Hey Aren,

    I am really struggling to use this project with Unity 3.5. I think there are a number of conversion issues; it might be good to make a note of this within the asset store for now until things get sorted out. Hopefully Unity fixes things on their side or you find a way to fix things on your side in the near future. Really liked what you provided, but I think we will have build from scratch.
  26. ArenMook

    ArenMook

    Member

    Joined:
    Oct 20, 2010
    Messages:
    1,901
    Sorry to hear that, and you're right I should mention that Unity guys are working on the fixes. What other issues are you seeing?
  27. WhiteRabbit

    WhiteRabbit

    New Member

    Joined:
    Jun 16, 2011
    Messages:
    13
    I just bought the kit and am pretty much lost trying to use the kit. I have Unity 3.5 and am new to it. Should I be able to select the Welcome Scene and play it or do I need to build with Welcome and Game scenes? It's crashing repeatedly when switching between scenes as well. I have been able to select an opening scene and play it to see how a kit works with other kits... doesn't seem to work in this case.

    I did unzip and copy the library into the library folder, btw - didn't help.
  28. ArenMook

    ArenMook

    Member

    Joined:
    Oct 20, 2010
    Messages:
    1,901
    @WhiteRabbit: The crashing on switching scenes is a bug in 3.5 that has been acknowledged by Unity and passed on to their devs to fix (case 443644). For Unity 3.5 you need to unzip the contents of that zip file into the ProjectSettings folder instead of Library (they changed it in that version). For building, you need to build it with Main and Game scenes selected. For playing, start with the Welcome screen (although you can start with the game scene right away, but it will be single-player only).
  29. WhiteRabbit

    WhiteRabbit

    New Member

    Joined:
    Jun 16, 2011
    Messages:
    13
    Ok, I copied the library zip contents into the ProjectSettings folder and now the Game scene can be played as a standalone. However, trying to play the Welcome Screen scene and clicking on "Host Game" does nothing. The Welcome dialog disappears briefly and pops up again. As an aside, I have the Photon server that I'm using with a non-Unity project and would like to use it within this demo.
  30. ArenMook

    ArenMook

    Member

    Joined:
    Oct 20, 2010
    Messages:
    1,901
    If clicking on Host Game does nothing then it sounds like it's failing to load the scene or start the server. Check your build properties, make sure that the Game scene has been added there. Are you getting any error messages? The game works fine for me when I start it via the Welcome screen on 3.5.0. Switching the scenes in the editor crashes Unity (that's the case 443644 bug I mentioned that Unity has to fix). I also get "Invalid scenehandle" error as soon as the game scene loads. Cryptic, reason unknown. The kit runs perfectly on 3.4.2. 3.5.0 has been far less stable in my experience.
  31. pqumsieh

    pqumsieh

    New Member

    Joined:
    Feb 28, 2012
    Messages:
    7
    Hey Aren,

    I am starting a new project but want to move over some of your work. I tried to compile the Spaceship, SpaceshipController, and FaceTarget script into a new script called PlayerController. However, the player movement is laggy causing the scene to appear to jitter. I tested to make sure this is the case, I imagine I have done something wrong to cause this.

    I removed the mNavigator and replaced it with generator.powerPercent. I tried to get rid of as much network script as possible and maintain just the basics. Could you take a look at the code and let me know if there is anything apparently wrong with it? I've been trying to figure out the jitters with no luck so far.

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. [RequireComponent(typeof(Rigidbody))]
    6. public class PlayerController : MonoBehaviour
    7. {
    8.     public PowerGenerator generator     = null;
    9.     public float maximumSpeed           = 150f;
    10.     public float mainThruster           = 1f;
    11.     public float maneuveringThrusters   = 1f;
    12.     public float turnThrusters          = 1f;
    13.     public float rotationSpeed          = 5f;
    14.     public float inertiaDampeners       = 0.15f;
    15.     public float boost                  = 2.0f;
    16.    
    17.     Rigidbody mRb = null;
    18.     Transform mTrans = null;
    19.     Quaternion mCurrentRot;
    20.     public bool movement = true;
    21.     Quaternion rot; // INFO: Used in FaceTarget script
    22.    
    23.     public Transform target;    // INFO: Used to force the player to face the selected target
    24.    
    25.     float mAppliedThrust    = 0f;   // Amount of thrust currently applied in any direction
    26.     //float mVelocity       = 0f;  // INFO: mVelocity was used by currentSpeed to display the current speed of the player on the HUD
    27.    
    28.     Vector3 mMove       = Vector3.zero;
    29.     Vector3 mSmoothMove = Vector3.zero;
    30.    
    31.     /// <summary>
    32.     /// Relative -1 to 1 range movement input.
    33.     /// </summary>
    34.     public Vector3 moveInput { get { return mMove; } set { mMove = value; } }
    35.    
    36.     // Use this for initialization
    37.     void Start ()
    38.     {
    39.         mRb = rigidbody;
    40.         mTrans = transform;
    41.        
    42.         if (generator == null)
    43.         {
    44.             generator = GetComponentInChildren<PowerGenerator>();
    45.         }
    46.     }
    47.    
    48.     // INFO: FixedUpdate runs the player movement script
    49.     void FixedUpdate()
    50.     {
    51.         // TODO: Add in PlayerMovement here
    52.         PlayerMovement();
    53.     }
    54.    
    55.     // INFO: Control input is handled within Update
    56.     void Update()
    57.     {
    58.         Vector3 move = this.moveInput;
    59.        
    60.         if (movement)
    61.         {
    62.             move.x = Input.GetAxis("Roll");
    63.             move.y = Input.GetAxis("Up");
    64.             move.z = Input.GetAxis("Forward");
    65.         }
    66.        
    67.         // Ensure the vector is unit length
    68.         float mag = move.magnitude;
    69.         if (mag > 1f) move *= 1.0f / mag;
    70.        
    71.         // Set the ship's values
    72.         this.moveInput = move;
    73.        
    74.         // INFO: Makes the player face the central enemy structure, smoothly handles rotations
    75.        
    76.         if (target != null)
    77.             {
    78.                 Vector3 dir = target.position - mTrans.position;
    79.                 float size = dir.magnitude;
    80.            
    81.             if (size > 0.001f)
    82.             {
    83.                 dir *= 1f / size;
    84.                
    85.                 if ((Input.GetAxis("Roll") != 0.00) || (Input.GetAxis("Up") != 0.00) || (Input.GetAxis("Forward") != 0.00))
    86.                 {
    87.                     rot = Quaternion.LookRotation(dir, transform.up);
    88.                 }
    89.                 else
    90.                 {
    91.                     rot = Quaternion.LookRotation(dir);
    92.                 }
    93.                
    94.                 mTrans.rotation = (rotationSpeed > 0f) ? Quaternion.Slerp(mTrans.rotation, rot, Time.deltaTime * rotationSpeed) : rot;
    95.             }
    96.            
    97.             rigidbody.constraints = RigidbodyConstraints.FreezeRotationZ | RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY;
    98.             }
    99.     }
    100.    
    101.     void LateUpdate()
    102.     {
    103.         // INFO: Tries to smooth the force applied to the player, refer to PlayerMovement;
    104.         //       I use it in mAppliedThrust to determine the amount of thrust applied to the player.
    105.         mSmoothMove = Vector3.Lerp(mSmoothMove, mMove, Mathf.Clamp01(Time.deltaTime * 10f));
    106.     }
    107.    
    108.     // INFO: Handles the forces that get applied to the player
    109.     void PlayerMovement()
    110.     {
    111.         // Ensure that we are not traveling faster than we are allowed to
    112.         Vector3 vel = mRb.velocity;
    113.  
    114.         // 3600 seconds in an hour, but 1000 meters in a km, 3600/1000=3.6
    115.         float speed = vel.magnitude * 3.6f;
    116.        
    117.         if (speed > maximumSpeed)
    118.         {
    119.             vel *= maximumSpeed / speed;
    120.             mRb.velocity = vel;
    121.         }
    122.        
    123.         // Amount of thrust being applied right now - mSmoothMove = Vector3
    124.         // DONE: Multiply mSmoothMove.magnitutde by the current percent within the power generator
    125.         mAppliedThrust = mSmoothMove.magnitude * generator.powerPercent;
    126.        
    127.         // No point in doing these calculations if the engine is idle
    128.         if (mAppliedThrust > 0.001f)
    129.         {
    130.             // Object's current local velocity
    131.             // Not sure why he is inversing the GObjects rotation and multiplying it by its velocity
    132.             vel = Quaternion.Inverse(mTrans.rotation) * vel;
    133.             float factor = 1000f * Time.deltaTime * mRb.mass;
    134.             float dampenerPower = (generator != null) ? (0.25f + 0.75f * generator.effectiveness) * inertiaDampeners : 0f;
    135.            
    136.             // mMove = Vector3
    137.             // INFO: Manually modifying each individual value within mMove and applying it later into appliedForce
    138.             // TODO: Play around with the controls scheme; ensure we are using forward, right, up correctly
    139.             float forward = mMove.z * mainThruster;
    140.             float right = mMove.x * maneuveringThrusters * 0.25f;
    141.             float up = mMove.y * maneuveringThrusters * 0.25f;
    142.            
    143.             // Calculate the force we want to apply to the ship
    144.             Vector3 appliedForce = new Vector3(right, up, forward);
    145.            
    146.             // Normalized direction of the applied force
    147.             float mag = appliedForce.magnitude;
    148.             // INFO: Force direction = either appliedForce * (1.0f / mag) or Vector3.forward
    149.             Vector3 forceDirection = (mag > 0.001f) ? appliedForce * (1.0f / mag) : Vector3.forward;
    150.            
    151.             // Applied force should take the current engine's power into account
    152.             appliedForce *= generator.powerPercent;
    153.            
    154.             // This is how much of velocity is currently what we need it to be:
    155.             // Q: What does this do?
    156.             Vector3 compatible = Vector3.Project(vel, forceDirection);
    157.            
    158.             // Dampener power depends on inertia dampeners strength as well as the current speed
    159.             dampenerPower *= 0.15f * speed / maximumSpeed;
    160.            
    161.             // This is the incompatible velocity (for side dampeners)
    162.             Vector3 dampeningForce = (compatible - vel) * dampenerPower;
    163.            
    164.             // If we're traveling in the opposite direction, we want to slow down first (in addition to the engine's force)
    165.             float dot = Vector3.Dot(vel, forceDirection);
    166.             if (dot < 0f) dampeningForce += vel * (dot * 0.1f * dampenerPower);
    167.            
    168.             // Apply the force and the incompatible velocity together
    169.             mRb.AddRelativeForce((dampeningForce + appliedForce) * factor);
    170.            
    171.             if(generator.powerPercent > 0.8f  Input.GetKey (KeyCode.Space)  Input.GetAxis("Forward") != 0)
    172.             {
    173.                 mRb.AddRelativeForce((dampeningForce + appliedForce) * factor * boost);
    174.                
    175.                 generator.DrainPower(10);
    176.                
    177.                 Debug.Log ("MORE POWER TO FORWARD THRUSTERS SCOTTY!");
    178.             }
    179.             Debug.Log (generator.powerPercent);
    180.         }
    181.         //INFO: mVelocity was used by currentSpeed to display the current speed of the player on the HUD
    182.         //mVelocity = Mathf.RoundToInt(mRb.velocity.magnitude * 3.6f);
    183.     }
    184. }
    185.  
    Thanks,
    Peter
  32. ArenMook

    ArenMook

    Member

    Joined:
    Oct 20, 2010
    Messages:
    1,901
    Jitters are caused by the camera moving in Update while the ship is moved in FixedUpdate (physics). I fixed it in the space game by adding a LagPosition script in-between of the two. It smooths out the jaggies, making them invisible.
  33. pqumsieh

    pqumsieh

    New Member

    Joined:
    Feb 28, 2012
    Messages:
    7
    Thanks for the reply Aren, I think we fixed the issue. I really appreciate your quick feedback and help; I've passed the word on about your starter kit as a thanks.

    Peter
  34. pqumsieh

    pqumsieh

    New Member

    Joined:
    Feb 28, 2012
    Messages:
    7
    Aren,

    Could you further explain how you implement LagPosition? Where is it called? I see that you use ChaseCamera to handle this movement.

    Cheers,
    Peter
  35. ArenMook

    ArenMook

    Member

    Joined:
    Oct 20, 2010
    Messages:
    1,901
    Simple hierarchy of 3 game objects:

    - Rigidbody
    --- LagPosition
    ------ Camera
  36. pqumsieh

    pqumsieh

    New Member

    Joined:
    Feb 28, 2012
    Messages:
    7
    The camera is a child of the player, I have attached lagPosition and LagRotation to the camera. Is there a step I am missing? It still jitters at this point. I also do not have your update manager incorporated but by looking at the script it doesn't seem to be referenced within lagposition/rotation.

    Peter
    Last edited: Mar 2, 2012
  37. ArenMook

    ArenMook

    Member

    Joined:
    Oct 20, 2010
    Messages:
    1,901
    Chase camera simply chases a target, and I believe it has similar code to lag position. LagPosition is just more flexible and more generic. (can't look at the code right now)
  38. WhiteRabbit

    WhiteRabbit

    New Member

    Joined:
    Jun 16, 2011
    Messages:
    13
    Just got back to this - Open the project, double-click on welcome screen - always crashes now, so can't add the scene to the build through the Add Current button. 3.5.0 has been out for quite a while - when are they planning to fix this? is it necessary to build the project or can the welcome scene simply be played? I don't really understand the difference between playing a scene and doing a build - the documentation for Unity isn't the best.

    At this point, I've payed $60 for nothing, since it's not usable in its present form and I was hoping to use the starter kit to begin to learn Unity. Will probably have to start over from scratch on the project and hope I can get back to being able to load the welcome scene. Is 3.4.2 still available and, if so, what are the differences?
  39. ArenMook

    ArenMook

    Member

    Joined:
    Oct 20, 2010
    Messages:
    1,901
    Unity 3.5.1 RC1 is currently out for testing, I'm hoping it addressed this issue but I haven't had a chance to test. 3.4.2 is much more stable than 3.5.0, if you can grab it and use it, I would suggest you do so. None of the features they added relate to the space game kit at all, so from my perspective 3.5.0 was just a step back rather than forward.
  40. WhiteRabbit

    WhiteRabbit

    New Member

    Joined:
    Jun 16, 2011
    Messages:
    13
    No luck in trying to find 3.4.2. Clicking on its link takes me to the 3.5 download page.

    After reloading the project, build options include all 3 scenes -- all grayed out and uncheckable. It's crashing every time that I double-click on the Welcome scene.

    So -- the kit is unusable as is with 3.5.0, 3.4.2 seems to be unavailable and the status of 3.5.1 is unknown. My earlier question remains as to whether I should be able to run the kit without compiling by playing the Welcome scene. If I have to compile, how do I do so when all scenes are unselectable in the build dialog?

    If 3.5.1 RC1 is out -- how does one get a hold of it?
  41. ArenMook

    ArenMook

    Member

    Joined:
    Oct 20, 2010
    Messages:
    1,901
    I am able to run the game by going to the welcome scene and hitting play. Hitting build makes Unity load scenes one at a time as it builds them, and switching scenes in 3.5.0 causes a crash, so the two don't mix.
  42. WhiteRabbit

    WhiteRabbit

    New Member

    Joined:
    Jun 16, 2011
    Messages:
    13
    Aren, I appreciate the rapid feedback, but we're not on the same page yet.

    1) I don't have 3.4.2 and know of no way to get it - do you know if it is available anywhere?
    2) You said 3.5.1 RC1 was out - do you know how to get it so I can see if it fixes the problem?
    2) Created a new project, importing the starter kit - Build options for the scenes are greyed out, Unzipped library and copied to ProjectSettings. Selecting Build results in a crash on first scene it tries to load. Any clue as to why I can't even build the project, or is it just 3.5?

    What I don't understand is why I can't reach the Welcome screen at all now -- it originally didn't crash every time, but now it does. The only difference I can think of is that I originally didn't copy the library files, then copied them to the library folder whereas this time I copied the files to the ProjectSettings folder per your instructions.

    I paid $60 for this starter kit and it is unusable as a multiplayer kit at this time - which is the primary reason why I purchased it. If you can't give me a solution, how do I get a refund?
    Last edited: Mar 6, 2012
  43. Crazy Robot

    Crazy Robot

    Member

    Joined:
    Apr 18, 2009
    Messages:
    931
    I have 3.4.2, send me a PM and I'll get it to you.
  44. WhiteRabbit

    WhiteRabbit

    New Member

    Joined:
    Jun 16, 2011
    Messages:
    13
    Thx - sent an email with my contact information to your contact listing on your website.
  45. ArenMook

    ArenMook

    Member

    Joined:
    Oct 20, 2010
    Messages:
    1,901
    @WhiteRabbit, I PM'd you yesterday with a download link. The crashes are all because of 3.5.0.
  46. Crazy Robot

    Crazy Robot

    Member

    Joined:
    Apr 18, 2009
    Messages:
    931
    Sorry, I only have the Mac version of 3.4.2.
  47. WhiteRabbit

    WhiteRabbit

    New Member

    Joined:
    Jun 16, 2011
    Messages:
    13
    Thx Aren, I have the 351 installed and it's not crashing. However, the scenes are still greyed out in the build dialog and cannot be selected (checked) for the build. I'm back to the original problem where clicking on "Host Game" in the Welcome screen results in the welcome dialog disappearing briefly and reappearing (so nothing happens). The console does report a series of errors.
    which are pretty cryptic.

    So - why are the scenes not checkable in the Build dialog? and if that's not the problem, then....?

    I added the scenes again, so there are now greyed out scenes (all 3 ) and two enabled scenes that I added. doing a build and then running it allowed me to play the game scene. However, if I played the wecome scene after this build, it did proceed to the game scene after selecting "Host Game".

    This is closer to functional, but still flaky. Welcome scene doesn't appear when running the compiled version, but does appear from running the welcome scene from within the editor.

    And, finally, rebuit adding welcome screen first followed by game scene and ... VOILA! Welcome scene now displays first and seems to work. What do ya know - there is a execution order that must be followed in adding scenes! Now, where in the world is the documentation that describes all this stuff? I could find nothing in the online reference manual about it (at least not through a cursory search).

    The greyed out scenes I could simply use the "Del" key on and then replace.

    Not looking forward to learning this engine by trial and error. Bought a couple of books which proved to be pretty much useless on many issues. Any suggestions on how to more efficiently learn this thing?

    Sorry if I appear to be a raving idiot and thx for the rapid feedback and the 351 download link.
    Last edited: Mar 6, 2012
  48. ArenMook

    ArenMook

    Member

    Joined:
    Oct 20, 2010
    Messages:
    1,901
    Unity references everything using metadata, including which scenes get included in the build. Greyed out simply means it can't find them. Re-adding them is the right way to go. I'm glad to hear that 3.5.1 fixed the issues though, that's a load off my back. :)
  49. bravery

    bravery

    Member

    Joined:
    Mar 26, 2009
    Messages:
    181
    Hi ArenMook,

    I just bought your space game starter kit.

    and it's crashing when I tried to open scenes sometimes, also in the welcome scene when I press Host game the welcome dialog disappear and reappear again, but the game do not start.

    Can you please advice about solution?

    Also as I can see up unity 3.5.1 solve the issue, where can I find the download link?

    Thanks in advance.
  50. bravery

    bravery

    Member

    Joined:
    Mar 26, 2009
    Messages:
    181
    Hi ArenMook,

    currently I'm playing with the kit, I can see from your well organized code that you have an interesting experiance.
    also the graphics and asset level is very good.

    I'm digging inside the code right now, even it's well organized but it's not easy to understand all the techniques that you are using right away.

    I'm thniking of using the GUI used in the kit with my own game, however I have a couple of questions:
    1- I can see you are using animation files to animate the GUI's can you please let me know how did you create these animations? did you use an exteral application? please explain?
    2- with a quick look for the script folder I can see there is GUI folder under Scripts and also there is a GUI folder under Script/Common/GUI, so what is the differenace between both of these folders? and why did you split the GUI to be in 2 seperate folders?
    3- My custom game that I have and I want to integrate your GUI code is using java script, so in this case I believe I need to move some of your GUI C# code to my StanderedAsset Floder, can you please let me know if this is correct? and what GUI files I need to move to my StanderedAsset folder to make the integration work?

    Thanks in advance.