Search Unity

Space Shooter Tutorial Q&A

Discussion in 'Community Learning & Teaching' started by Adam-Buckner, Mar 26, 2015.

  1. Injaa

    Injaa

    Joined:
    Aug 3, 2016
    Posts:
    3
    Hey I'm Having a Problem where the Enemy Ships are just staying just offscreen and not coming down. IDK what the problem is or how to fix it..
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Done_EvasiveManeuver : MonoBehaviour
    5. {
    6.     public Done_Boundary boundary;
    7.     public float tilt;
    8.     public float dodge;
    9.     public float smoothing;
    10.     public Vector2 startWait;
    11.     public Vector2 maneuverTime;
    12.     public Vector2 maneuverWait;
    13.  
    14.     private float currentSpeed;
    15.     private float targetManeuver;
    16.  
    17.     void Start ()
    18.     {
    19.         currentSpeed = GetComponent<Rigidbody>().velocity.z;
    20.         StartCoroutine(Evade());
    21.     }
    22.    
    23.     IEnumerator Evade ()
    24.     {
    25.         yield return new WaitForSeconds (Random.Range (startWait.x, startWait.y));
    26.         while (true)
    27.         {
    28.             targetManeuver = Random.Range (1, dodge) * -Mathf.Sign (transform.position.x);
    29.             yield return new WaitForSeconds (Random.Range (maneuverTime.x, maneuverTime.y));
    30.             targetManeuver = 0;
    31.             yield return new WaitForSeconds (Random.Range (maneuverWait.x, maneuverWait.y));
    32.         }
    33.     }
    34.    
    35.     void FixedUpdate ()
    36.     {
    37.         float newManeuver = Mathf.MoveTowards (GetComponent<Rigidbody>().velocity.x, targetManeuver, smoothing * Time.deltaTime);
    38.         GetComponent<Rigidbody>().velocity = new Vector3 (newManeuver, 0.0f, currentSpeed);
    39.         GetComponent<Rigidbody>().position = new Vector3
    40.         (
    41.             Mathf.Clamp(GetComponent<Rigidbody>().position.x, boundary.xMin, boundary.xMax),
    42.             0.0f,
    43.             Mathf.Clamp(GetComponent<Rigidbody>().position.z, boundary.zMin, boundary.zMax)
    44.         );
    45.        
    46.         GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, 0.0f, GetComponent<Rigidbody>().velocity.x * -tilt);
    47.     }
    48. }
    49.  
    Is there anything wrong in here?
     
  2. ladyonthemoon

    ladyonthemoon

    Joined:
    Jun 29, 2015
    Posts:
    236
    The script you posted is the one Unity provides with the project in case of need. Post your own script so that we can see what's wrong in it. :)
     
  3. SquareSpiralStudios

    SquareSpiralStudios

    Joined:
    Aug 3, 2016
    Posts:
    5
    Hello all!

    I'm super new to the entire game development, thing, but I'm having a great time learning all this cool stuff! In just the past few days, I've completed my first game (the roll-a-ball tutorial one, but IT COUNTS! XD), started a project of my own, and now tackling this Space Shooter madness!

    Everything has been going fine, I got my ship to move and tilt, got the scene lit up and all, but when it comes to firing the bolt I'm getting a strange error message.

    At first, everything seemed to work fine; I enter play mode, my ship moves, I click, and the bolts fire. Not bad! But wait, if I stop firing, and the final bolt leaves the game box and gets destroyed, my ship won't fire any more bolts :(

    I notice that in the game hierarchy when the bolt is fired, it's recognized by Unity as a "clone" and each successive bolt adds another "clone" identifier. So, if I've fired 5 bolts, in the hierarchy, the fifth bolt is named Bolt (clone)(clone)(clone)(clone), and if I stop firing, Unity destroys this bolt along with the bolt prefab linked to the "shot" reference on the player game object. I am a utter and complete novice, so I have no idea what I did wrong, but Unity is throwing up this error: MissingReferenceException: The object of type 'GameObject' has been destroyed, but you are still trying to access it.

    Is there anyplace where I could examine fully functioning code to see if there's an error in my scripting? Or does anyone have any general insight into what is going on here? Any help would be greatly appreciated! Mucho thanks! Much cheers! Wow!!
     
  4. Injaa

    Injaa

    Joined:
    Aug 3, 2016
    Posts:
    3
    oops I copied the done code by mistake as i was comparing it to my own and forgot to switch back.
    Here is my code
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class EvasiveManeuver : MonoBehaviour {
    5.  
    6.     public float tilt;
    7.     public float smoothing;
    8.     public float dodge;
    9.     public Vector2 startWait;
    10.     public Vector2 maneuverTime;
    11.     public Vector2 maneuverWait;
    12.     public Boundary boundary;
    13.  
    14.     public float currentSpeed;
    15.     public float targetManeuver;
    16.     private Rigidbody rb;
    17.  
    18.     void Start () {
    19.         rb = GetComponent<Rigidbody>();
    20.         StartCoroutine(Evade());
    21.         currentSpeed = rb.velocity.z;
    22.  
    23.     }
    24.  
    25.     IEnumerator Evade()
    26.     {
    27.         yield return new WaitForSeconds(Random.Range(startWait.x, startWait.y));
    28.  
    29.         while (true)
    30.         {
    31.             targetManeuver = Random.Range(1,dodge) * Mathf.Sign(transform.position.x);
    32.             yield return new WaitForSeconds(Random.Range(maneuverTime.x,maneuverTime.y));
    33.             targetManeuver = 0;
    34.             yield return new WaitForSeconds(Random.Range(maneuverWait.x,maneuverWait.y));
    35.         }
    36.     }
    37.     void FixedUpdate () {
    38.  
    39.         float newManeuver = Mathf.MoveTowards(rb.velocity.x, targetManeuver, Time.deltaTime * smoothing);
    40.         rb.velocity = new Vector3(newManeuver,0.0f, currentSpeed);
    41.         rb.position = new Vector3(Mathf.Clamp(rb.position.x, boundary.xMin,boundary.xMax), 0.0f,Mathf.Clamp(rb.position.z,boundary.zMin,boundary.zMax) );
    42.         rb.rotation = Quaternion.Euler(0.0f, 0.0f, rb.velocity.x * -tilt);
    43.     }
    44. }
    45.  
     
    Last edited: Aug 3, 2016
  5. Jarryd7786

    Jarryd7786

    Joined:
    Jul 24, 2016
    Posts:
    17
    Hey I just did this and had some of my own issues, um it looks like your Bolts are being fired from the shotspawn but the shotspawn isn't attached to your enemy ships script 'Weapon Controller' from what I see it definitely looks like that.
    Does yours look something like that?
     

    Attached Files:

  6. Jarryd7786

    Jarryd7786

    Joined:
    Jul 24, 2016
    Posts:
    17
    Alright I have a question too, on the space shooter how would I go about adding lives and like once you reach 5000 or so points a boss spawns that has a life bar and doesn't get damaged by the other hazards that come down. because I'm keen to develop this further and make my own hazards and stuff and change the free assets that I imported.
    :)
     
  7. Behzad65

    Behzad65

    Joined:
    Aug 5, 2016
    Posts:
    8
    Hi all, i have followed the tutorial to the end of the player shooting, and i have this problem, the player dose not shoot! i double checked every thing , no error or something. but the player dose not shoot. :(.

    here is my script:






    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. [System.Serializable]
    4. public class Boundary
    5. {
    6.     public float xMin,xMax,zMin,zMax;
    7. }
    8.  
    9. public class PlayerControler : MonoBehaviour {
    10.  
    11.     private Rigidbody rb;
    12.     public float speed;
    13.     public float tilt;
    14.     public Boundary boundary;
    15.  
    16.     public GameObject shot;
    17.     public Transform shotSpawn;
    18.     public float fireRate;
    19.  
    20.     private float nextFire;
    21.  
    22.  
    23.     void Start()
    24.     {
    25.         rb= GetComponent<Rigidbody> ();
    26.     }
    27.  
    28.     void update()
    29.     {
    30.         if (Input.GetButton("Fire1") && Time.time > nextFire)
    31.         {
    32.             nextFire = Time.time + fireRate;
    33.             Instantiate (shot, shotSpawn.position, shotSpawn.rotation);
    34.         }
    35.     }
    36.  
    37.  
    38.  
    39.     void FixedUpdate ()
    40.     {
    41.         float moveHorizontal = Input.GetAxis ("Horizontal");
    42.         float moveVertical = Input.GetAxis ("Vertical");
    43.         Vector3 movement= new Vector3(moveHorizontal, 0.0f,moveVertical);
    44.         rb.velocity = movement * speed;
    45.         rb.position = new Vector3
    46.             (
    47.             Mathf.Clamp (rb.position.x, boundary.xMin,boundary.xMax),
    48.             0,
    49.             Mathf.Clamp (rb.position.z, boundary.zMin,boundary.zMax)
    50.             );
    51.         rb.rotation = Quaternion.Euler (rb.velocity.z * tilt/2, 0, rb.velocity.x * -tilt );
    52.  
    53.  
    54.    
    55.     }
    56.  
    57. }
    58.  
     
  8. SirSkorpan

    SirSkorpan

    Joined:
    Jun 14, 2016
    Posts:
    5
    I don't seem to be able to build a web version of the space shooter. I'm using Unity 5.4 and since there was no "Web Player" option I chose WebGL. Though, when I try to build I get no files in the folder I choose. I can build a standalone version, though the texts are positioned to the side of the game view (in the back, when in full screen). Where do I start looking for solutions to this?

    As a side note there is no option to choose an aspect ratio that matches the WebGL's resolution settings, in my game view I can only choose standalone, but if I choose for example Android as build target I get a whole bunch of standard resolutions for that (portrait landscape and what not).

    Couldn't find anything about these issues in the "upgrade guide" for the tutorial, is it related to my installation or is there something that changed, which caused this, for 5.4?
     
    Vaheyla likes this.
  9. Ulux

    Ulux

    Joined:
    Aug 5, 2016
    Posts:
    1
    Same here. I wanted to start the space shooter tutorial today but I don't know what to do with build settings.
     
  10. Jarryd7786

    Jarryd7786

    Joined:
    Jul 24, 2016
    Posts:
    17
    It looks like 'line 9.' 'Controller' is spelled with one 'L' instead of two and try moving the '{' down one as well ^_^ as I can see that's all that looks incorrect with it. Also check that spelling is correct in all files and Scripts. :)
     
  11. Jarryd7786

    Jarryd7786

    Joined:
    Jul 24, 2016
    Posts:
    17
    How would I go about making a boss ship spawn under these conditions.

    1) score: 5000
    2) multiple hits (life bar)
    3) not affected by other hazards

    Looking into this quite a lot.
     
  12. SirSkorpan

    SirSkorpan

    Joined:
    Jun 14, 2016
    Posts:
    5
    Well I'm no pro but my suggestion is:

    The responsibility for holding the score and recalculating it as well as spawning enemies/hazards seems to be the GameController. It seems logical to put in a check in this class, perhaps let the game controller check if the 5000 mark has been reached each time a new score is added. If this happens I guess one would let the controller spawn a boss in the same way it spawns waves of hazards (just not in a for loop as we just want one).

    Assuming you already have the modells/textures and what not for the boss enemy I suppose the life bar would be a property of the boss character probably an int field holding the number of hits the boss can take, I'd guess the int field should be held in a "BossController" script or similar, attached to the boss. For it to not be affected by other hazards you'd have to modify the destroy on contact script. You'd have to check, at contact, if the other.tag == "Boss" (a tag you'd have to add to the boss character) similar to how the boundary and player is detected already. In fact, you could just return as we do with the boundary.

    Now you want the bolts to affect the boss if the player hits it with the bolts. I suggest a new script "DeductHealthOnHit" or something similar. I'd guess one would put it on the bolt. This script should detect OnTriggerEnter if the other.tag == "Boss" (or any other tag that have HP) and deduct 1 from the HP field mentioned above. Taking away the 1 would probably be done by calling a "DeductHP()" method in "BossController". A reference to the "BossController" would be achieved by something like other.GetComponent<BossController>() after you've detected a hit with a Boss object.

    Once the HP counter in "BossController" reaches 0 you'd, call a method in "BossController" to destroy the boss and raise a flag in the GameController I suggest a bool levelCleared flagg that would work similar to the gameOver flagg but instead show a congratulatory message.

    Hope that gets you started, I leave the details for practice ;)
     
    Last edited: Aug 6, 2016
  13. SirSkorpan

    SirSkorpan

    Joined:
    Jun 14, 2016
    Posts:
    5
    I figured out why the WebGL build didn't work, it was because I had non ASCII characters in my path-name (there actually was an error there in the editor that I missed yesterday). Fixed that up and now I have a WebGL build of the space shooter.

    In my case I had a "ä" (a letter used in Sweden, and a few other countries :)) and after removing that (and a space for good measure) it worked fine.

    Don't know if that was Vilebrequin's problem as well but could be worth a look.

    As a side note unless you have a web server to put the built game on use FireFox to open it. FF was the only browser I had that could play WebGL stuff from the hard drive.
     
    Last edited: Aug 6, 2016
  14. Injaa

    Injaa

    Joined:
    Aug 3, 2016
    Posts:
    3
    Hey I'm Having a Problem where the Enemy Ships are just staying just offscreen and not coming down. I don't know what the problem is or how to fix it..
    Here's my Code
    Code (CSharp):
    1.     using UnityEngine;
    2.     using System.Collections;
    3.    
    4.     public class EvasiveManeuver : MonoBehaviour {
    5.    
    6.         public float tilt;
    7.         public float smoothing;
    8.         public float dodge;
    9.         public Vector2 startWait;
    10.         public Vector2 maneuverTime;
    11.         public Vector2 maneuverWait;
    12.         public Boundary boundary;
    13.    
    14.         public float currentSpeed;
    15.         public float targetManeuver;
    16.         private Rigidbody rb;
    17.    
    18.         void Start () {
    19.             rb = GetComponent<Rigidbody>();
    20.             StartCoroutine(Evade());
    21.             currentSpeed = rb.velocity.z;
    22.    
    23.         }
    24.    
    25.         IEnumerator Evade()
    26.         {
    27.             yield return new WaitForSeconds(Random.Range(startWait.x, startWait.y));
    28.    
    29.             while (true)
    30.             {
    31.                 targetManeuver = Random.Range(1,dodge) * Mathf.Sign(transform.position.x);
    32.                 yield return new WaitForSeconds(Random.Range(maneuverTime.x,maneuverTime.y));
    33.                 targetManeuver = 0;
    34.                 yield return new WaitForSeconds(Random.Range(maneuverWait.x,maneuverWait.y));
    35.             }
    36.         }
    37.         void FixedUpdate () {
    38.    
    39.             float newManeuver = Mathf.MoveTowards(rb.velocity.x, targetManeuver, Time.deltaTime * smoothing);
    40.             rb.velocity = new Vector3(newManeuver,0.0f, currentSpeed);
    41.             rb.position = new Vector3(Mathf.Clamp(rb.position.x, boundary.xMin,boundary.xMax), 0.0f,Mathf.Clamp(rb.position.z,boundary.zMin,boundary.zMax) );
    42.             rb.rotation = Quaternion.Euler(0.0f, 0.0f, rb.velocity.x * -tilt);
    43.         }
    44.     }
    45.    
    46.  
     
  15. SirSkorpan

    SirSkorpan

    Joined:
    Jun 14, 2016
    Posts:
    5
    Did you add the Mover script and set a speed to the enemy? The EvasiveManeuver class dosen't move the enemyships in the Z-direction
     
  16. drhmiri

    drhmiri

    Joined:
    Jun 17, 2014
    Posts:
    82
    I downloaded the latest Unity version, though I did not check the Web Player option before installation. Now, I am following this tutorial that requires that, so I downloaded the Web Player and ran it, but it does not appear in my Build Settings under Platform. How do I include it in my Unity installation?
     
  17. Deleted User

    Deleted User

    Guest

    The web player is deprecated with Unity 5.4, try WebGL, instead.

    If WebGL is not in the build options, install it by running the Unity 5.4 download assistant and uncheck everything except "WebGL Build Support" at the bottom of the list.
     
    davidhyte and drhmiri like this.
  18. milos2899

    milos2899

    Joined:
    Aug 11, 2016
    Posts:
    2
    void Update ()
    {
    if (Input.GetButton("Fire1") && Time.time > nextFire)
    {
    nextFire = Time.time + fireRate;
    Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
    }
    }
    I cant see my fire bolt when i click the mouse,whats the problem? Did I need to change something in code or i have problem with unity componnent.
     
  19. Deleted User

    Deleted User

    Guest

  20. milos2899

    milos2899

    Joined:
    Aug 11, 2016
    Posts:
    2
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. [System.Serializable]
    5. public class Boundary
    6. {
    7.     public float xMin, xMax, zMin, zMax;
    8. }
    9.  
    10. public class PlayerController : MonoBehaviour
    11. {
    12.     public float speed;
    13.     public float tilt;
    14.     public Boundary boundary;
    15.  
    16.     public GameObject shot;
    17.     public Transform shotSpawn;
    18.     public float fireRate;
    19.  
    20.     private float nextFire;
    21.  
    22.     void Update ()
    23.     {
    24.         if (Input.GetButton("Fire1") && Time.time > nextFire)
    25.         {
    26.             nextFire = Time.time + fireRate;
    27.             Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
    28.         }
    29.     }
    30.  
    31.     void FixedUpdate ()
    32.     {
    33.         float moveHorizontal = Input.GetAxis ("Horizontal");
    34.         float moveVertical = Input.GetAxis ("Vertical");
    35.  
    36.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    37.         rigidbody.velocity = movement * speed;
    38.  
    39.         rigidbody.position = new Vector3
    40.         (
    41.             Mathf.Clamp (rigidbody.position.x, boundary.xMin, boundary.xMax),
    42.             0.0f,
    43.             Mathf.Clamp (rigidbody.position.z, boundary.zMin, boundary.zMax)
    44.         );
    45.  
    46.         rigidbody.rotation = Quaternion.Euler (0.0f, 0.0f, rigidbody.velocity.x * -tilt);
    47.     }
    48. }
     
  21. drhmiri

    drhmiri

    Joined:
    Jun 17, 2014
    Posts:
    82
    At the point of replacing the player's complex mesh renderer (having added a mesh collider) with the provided simple mesh, my Unity Editor would not allow me to drag and drop it on top of the Mesh Collider's Mesh. Even when I click on the little dot to find it and add it manually, I still cannot do it. Am I missing something?
     
  22. hektorj

    hektorj

    Joined:
    Aug 13, 2016
    Posts:
    3
    Hi,
    I have a problem with the momevent. On play mode, the ship moves forward without pressing any button. I did everything that the video said and the guide. Here is the code:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PlayerController : MonoBehaviour {
    5.  
    6.     private Rigidbody rb;
    7.     public float speed;
    8.  
    9.     void Start()
    10.     {
    11.         rb = GetComponent<Rigidbody>();
    12.     }
    13.  
    14.     void FixedUpdate()
    15.     {
    16.         float moveHorizontal = Input.GetAxis("Horizontal");
    17.         float moveVertical = Input.GetAxis("Vertical");
    18.  
    19.         Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
    20.         rb.velocity = movement * speed;
    21.     }
    22. }
    23.  
     
    Last edited: Aug 13, 2016
  23. Ashdroid

    Ashdroid

    Joined:
    Aug 14, 2016
    Posts:
    1
    Guys, I've just begun with the Space Shooter tutorial. I got the Unity Web Player downloaded but still it doesn't work in Firefox. Because of this very reason, in the 'Build settings' of the project, I don't have the 'Web Player' option in the dropdown list. Somehow, not able to fix this issue even after going through many questions in the forums.
     
  24. Deleted User

    Deleted User

    Guest

    See my message above: http://forum.unity3d.com/threads/space-shooter-tutorial-q-a.313899/page-38#post-2748514
     
  25. Fleshbits

    Fleshbits

    Joined:
    Aug 11, 2016
    Posts:
    3
    I am confused when the tutorial sets the velocity of the rigid body belonging to the prefab bolt object, the narrator uses transform.forward * speed;

    Whose transform is it? the bolt's?
    What is the forward member of a transform? When I hear transform, I am thinking of 4x4 matrix. Is transform.forward _b3 of the matrix? The mouse over tool tip says the blue axis in world space..., but that seems to be zero, so I don't know how it is moving.

    Can someone break down what's going on there a little more?

    Also, I am not sure if this is already asked in this thread. Is there some means to search a single thread? It is 38 pages longs now.

    Thanks.
     
    Last edited: Aug 15, 2016
  26. sadaf550

    sadaf550

    Joined:
    Jul 4, 2016
    Posts:
    9
    hi I am an ABSOLUTE unity 3d beginner and your tutorials makes me feel like a pro :D !
    Anywayysss,
    I am having some problem in my space shooter game, I have followed everything but my enemy ship won't come forward when my evasiveManeuver script is on... I mean, it moves forward, like other hazards, only when the evasiveManeuver script is off. The evasiveManeuver script works fine on its own as the enemy ship move left, right, dodges the boundaries...
    What must be the issue? :/

    On the second thought, here are the scripts:

    The evasiveManeuver script:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class EvasiveManeuver : MonoBehaviour {
    5.  
    6.     public Vector2 startwait;
    7.     public float dodge;
    8.     public Vector2 maneuverTime;
    9.     public Vector2 maneuverWait;
    10.     public float smoothing;
    11.     public Boundary boundary;
    12.     public float tilt;
    13.  
    14.  
    15.     private float targetManeuver;
    16.     private Rigidbody rb;
    17.     private float CurrentSpeed;
    18.  
    19.     void Start ()
    20.     {
    21.         rb = GetComponent<Rigidbody> ();
    22.         CurrentSpeed = rb.velocity.x;
    23.         StartCoroutine (Evade ());
    24.     }
    25.  
    26.     IEnumerator Evade()
    27.     {
    28.         yield return new WaitForSeconds (Random.Range (startwait.x, startwait.y));
    29.  
    30.         while (true)
    31.         {
    32.             targetManeuver = Random.Range (1, dodge)* -Mathf.Sign(transform.position.x);
    33.             yield return new WaitForSeconds (Random.Range(maneuverTime.x,maneuverTime.y));
    34.             targetManeuver = 0;
    35.             yield return new WaitForSeconds (Random.Range(maneuverWait.x, maneuverWait.y));
    36.         }
    37.     }
    38.  
    39.     void FixedUpdate ()
    40.     {
    41.         float newmaneuver = Mathf.MoveTowards (rb.velocity.x, targetManeuver, Time.deltaTime * smoothing);
    42.         rb.velocity = new Vector3 (newmaneuver, 0.0f, CurrentSpeed);
    43.         rb.position = new Vector3
    44.         (
    45.                 Mathf.Clamp(rb.position.x, boundary.xMin, boundary.xMax)
    46.                 ,0.0f,
    47.                 Mathf.Clamp(rb.position.z, boundary.zMin,boundary.zMax)
    48.         );
    49.         rb.rotation = Quaternion.Euler (0.0f, 0.0f, rb.velocity.x * -tilt);
    50.     }
    51. }
    52.  
    The mover script:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.Scripting;
    4.  
    5. public class mover : MonoBehaviour
    6. {
    7.     public Rigidbody rb;
    8.     public float speed;
    9.  
    10.     void Start ()
    11.     {
    12.         rb.GetComponent <Rigidbody> ();
    13.         rb.velocity = transform.forward * speed;
    14.     }
    15. }
    16.  
    Thank you in advance...
     
    Last edited: Aug 16, 2016
  27. DiHand79

    DiHand79

    Joined:
    Dec 27, 2015
    Posts:
    1
    A good lesson , I made it to the 5th version and it works. But I want to do it their own way. It does not get just such a beautiful background of the space as you have done. Please tell me how you did it .
     
  28. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    transform.forward is basically shorthand for a Vector3 with values for x, y, z of (0f, 0f, 1f).
    generally when an object is created its default rotation is that the forward is pointing down the Z axis (the blue one on the gizmo) into the screen.

    when using transform (lower case) you are using the transform of the object instance that the script is attached to, in this case our bolt instance.

    so you could have used velocity = new Vector3(0f, 0f, 1f) * speed, but just neater to use the forward shorthand and then multiply it to give a velocty vector to apply to the rigidbody.

    probably a better explanation
    http://forum.unity3d.com/threads/what-is-transform-forward.338384/
     
    Last edited: Aug 17, 2016
  29. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836

    Just having a quick look at your EvasiveManouver script, on line 22 you currently have
    Code (CSharp):
    1. CurrentSpeed = rb.velocity.x;
    but it should be checking the Z velocity as thats the direction of forward movement for the enemies.
    Code (CSharp):
    1. CurrentSpeed = rb.velocity.z;
    if that still doesnt sort it, might be worth comparing yours and Adams scripts from here.
    http://unity3d.com/learn/tutorials/...e-shooter-enemies-more-hazards?playlist=17147
     
  30. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    If it is an image of a space nebula / background your looking for there are loads of free pictures either on the asset store, or just do a google search for free backgrounds for commercial and personal use.
    but always check the terms of use as well on any assets or images.
    https://www.google.co.uk/search?btn...l+use&gws_rd=cr,ssl&ei=Y3qzV7zHM6XCgAbhqpGwBQ
     
  31. matthis42

    matthis42

    Joined:
    Aug 17, 2016
    Posts:
    2
    image erreur.png
    Hello I am a unity 3d begginer and I am at the tutorials 5 of space shooter. I don't know how resolve these errors. I make exactly like the tutorials.
     
  32. Magor

    Magor

    Joined:
    Aug 18, 2016
    Posts:
    2
    Hello!

    I got some problem. I finish lesson 1.5 "Moving the player", but... When ship reach boundary, for example left (minX=-6), it doesn't stop. If I still pressing left arrow key on keyboard, ship slowly fly out of boundary. And very slowly come back, when I press right arrow.

    I can't find out, why it so? In lesson ship stops, when reach boundary, but my not.
     
  33. brunomendoza

    brunomendoza

    Joined:
    Sep 19, 2015
    Posts:
    1
    Hi all,

    WebPlayer platform option is deprecated. You can substitute it for WebGL and set its resolution to 600 per 900 but when you run the game this resolution its not adopted by viewport.

    What can we do to fix this issue?
     
  34. sadaf550

    sadaf550

    Joined:
    Jul 4, 2016
    Posts:
    9
    Thanku OboShape for your reply, I still couldnt resolve my problem tho, I did check the code of evasivemaneuver, I even replaced my code with the one given under the tutorial, but the problem persists :(
    My enemy ships wont come down with evasiveManeuver script on :/
     
  35. sadaf550

    sadaf550

    Joined:
    Jul 4, 2016
    Posts:
    9
    check your scripts, compare it with the ones given under the tutorials..
     
  36. sadaf550

    sadaf550

    Joined:
    Jul 4, 2016
    Posts:
    9
    you must be missing the scripts,
    attach a script on the player gameobject, u can do this by clicking on the "Player" than clicking on the "add component", select "scripts" , select the required script i.e "Player Controller"
     
  37. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Hmm, any chance you can upload the project so I can get a look at it please.
    other than that not sure, I did try your script, and they just stayed at the top as well.
    then I change the start method of the evasivemanouver script to this
    Code (CSharp):
    1.     void Start ()
    2.     {
    3.         rb = GetComponent<Rigidbody> ();
    4.         CurrentSpeed = rb.velocity.z;
    5.         StartCoroutine (Evade ());
    6.     }
    7.  
    and it seemed to work correctly, strange one sorry
     
  38. matthis42

    matthis42

    Joined:
    Aug 17, 2016
    Posts:
    2
    I create a new project and I import space shooter's package contents but it doesn't work. I don't understand image erreur 2.png
     
  39. sadaf550

    sadaf550

    Joined:
    Jul 4, 2016
    Posts:
    9
    these are just warnings about the Done assets (provided by the unity people), ignore them ..
    it wont bother ur project..
     
  40. sadaf550

    sadaf550

    Joined:
    Jul 4, 2016
    Posts:
    9
    It didnt work for me, they still stood there.
    I dont know how to send u the project...
     
  41. Magor

    Magor

    Joined:
    Aug 18, 2016
    Posts:
    2
    Hello!

    I try to add new feature to game: with every new wave speed of asteroids increase.
    When I try to do so, asteroids don't spawn in game, but there no errors in console. I can fly, shoot, but there are no asteroids at all (

    Could someone help me?
    1.jpg
     
  42. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Sorry been away at work, could just zip the project folder up and then upload to dropbox or similar.
    Not sure what to suggest, possibly rewatch the video and check the inspector and object settings as you go through.
     
  43. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    I'm making a couple of assumptions, it would be best if you could post any code in your post, using the code tags (see sig) means we can copy parts of the script to test and it makes it easier to read.

    This has been mentioned in the thread previously, so might be worth a search.

    But, during the instantiating of hazards you could grab the reference to that object as you instantiate it and set the speed there and then, rather than doing a search by tag.
    Code (CSharp):
    1. GameObject tempObj =  Instantiate(hazard, spawnPosition, spawnRotation) as GameObject;
    2.                 tempObj.GetComponent<MoverHazard>().IncreaseSpeed(waveCount);
     
  44. lkovtynovich

    lkovtynovich

    Joined:
    Aug 27, 2016
    Posts:
    1
    Apparently in version 5.4 they stopped supporting Web Player. WebGL replaces it. Basically the browsers (Chrome, Firefox, IE) stopped supporting the plugin type used by Web Player (NPAPI I believe), therefore it isn't/won't be relevant in the near future. Not sure yet what kind of issues this will cause in the tutorial as I just started it myself. Hopefully they'll update the upgrade guide if there are...
     
  45. Mordetherelicor

    Mordetherelicor

    Joined:
    Aug 28, 2016
    Posts:
    2
    Hello!

    I've gotten to the end of the tutorial and am now at the stage where I want to add my own things to the game. A problem I've run into is with the mover system. I'm trying to implement a power up element to the game and have changing shot types. In the extended video the host was able to do it just by changing the Y rotation on the new shotSpawns. I've tried doing the same but with no luck, they still shoot forward. So now I'm trying to make a new mover script just for the angle shots but I feel that I'm doing it wrong and that there is an easier way than separating 2 of my spawn locations completely. I currently have 4 power levels, 1 2 and 4 all shoot properly because they're just directed forward but I want 3 to have one shoot in the center and 2 out at say 30 degrees each way.

    The other part of this is where to start at making enemies randomly drop powerups at a percentage chance or at certain point levels. Thanks in advance.

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class MoverAngles : MonoBehaviour
    6. {
    7.  
    8.   private Rigidbody rb;
    9.   public float speed;
    10.   public float anglex;
    11.   public float anglez;
    12.  
    13.   void Start ()
    14.   {
    15.   rb = GetComponent<Rigidbody>();
    16.  
    17.   rb.velocity = transform.eulerAngles = new Vector3(anglex, 0.0f, anglez); //shoots faster with more angle...
    18.   }
    19.    
    20. }
    21.  
     
  46. arjunr24724

    arjunr24724

    Joined:
    Nov 28, 2014
    Posts:
    9
    Hi

    I find that the movement of the spaceship becomes slightly jerky if I increase the speed. Enabling Interpolation on the Rigidbody improves the animation but breaks the boundary code where it starts jerking at the edges of the screen probably because it is interpolating to a position outside the boundary but getting clamped back because of our boundary code.

    Is there a better way to move the spaceship using something like Lerp to make the animation smoother? Or is there an alternative movement code based on kinematic rigidbody that makes the whole animation smooth at any speed?

    PS: My spaceship has only one Rigidbody in the hierarchy but it does have mesh components and particle systems in the hierarchy.
     
  47. Catalyst_oneamongstthem

    Catalyst_oneamongstthem

    Joined:
    Aug 31, 2016
    Posts:
    1
    Hey guys
    I can't select the web player option in the build options, which is supposed to appear over the standalone option. Just isn't there. Please help. As you can see below, it is missing. I am following the Space shooter tutorial on the website. Screenshot (9).png
     
  48. saYram

    saYram

    Joined:
    Sep 1, 2016
    Posts:
    1
    Unity 5.4 no longer have Web Player support. 5.2 and 5.3 can build but 5.4 does not. Use WebGL instead of Web Player.
     
  49. Ilya_Zaitsev

    Ilya_Zaitsev

    Joined:
    Sep 6, 2016
    Posts:
    1

    Hello, guys!

    Looks like I have a similar problem.

    Have a trouble with part "Creating Hazard". I made an Asteroid and added the Rotation script to it, but after launching the game mode, position of Asteroid changed and kept changing every moment. I tried to find the solving of this problem and i found that the Capsule collider's Height and Radius affects on position. I don't know how to fix it. If I set these properties to null, interaction with Asteroid becoming impossible.
     

    Attached Files:

  50. Wolfgabe

    Wolfgabe

    Joined:
    Sep 4, 2016
    Posts:
    131
    Almost done with the tutorial just a few problems to take care of. For some reason all of a sudden my ship insists on veering straight to the right and sticking there when I go to test. Also when I go to build for some reason it only says choose folder in the save dialogue box