Search Unity

Space Shooter Tutorial Q&A

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

  1. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    The web player has been deprecated and no longer available, so you will have to use the WebGL platform, which gives similar results.

    Dont know, personally ive not looked into it that much, i guess, but you have done the right thing in this instance by adding a custom resolution. the only way ive found when i tried it tonight was to change the PC standalone resolution, and then from the aspect resolution dropdown to 'standalone', it will update then when changing the standalone resolution.

    but for WebGL, just adding a custom seems to be the best option atm.

    could be the skybox showing as opposed to a solid color.

    think these settings are now under the lighting tab, going to window > lighting.

    for that might be worth looking at the unity 5 upgrade guide for this project, which can be found here ( or on the main space shooter tutorial page on Unity learn site)
    https://oc.unity3d.com/index.php/s/rna2inqWBBysn6l?_ga=1.146452343.2123906831.1439472317


    hope that helps slightly to get you rolling again.
     
    Last edited: Dec 27, 2016
  2. igorkostan

    igorkostan

    Joined:
    Dec 24, 2016
    Posts:
    3
    Thank you OboShape, you helped me a lot.
     
  3. Guy_incognito97

    Guy_incognito97

    Joined:
    Dec 6, 2016
    Posts:
    1
    Thank you, this was driving me crazy but I was also missing the capital S.
     
  4. CarlJFoster

    CarlJFoster

    Joined:
    Dec 26, 2016
    Posts:
    5
    Hi I've solved the problem. Turns out it was an issue with my mouse/touchpad settings, so nothing to do with unity or the code.

    Thanks anyway.
     
  5. Hoffes

    Hoffes

    Joined:
    Oct 21, 2016
    Posts:
    4
    Hey Guys, im wondering why in this Code:


    PlayerTarget.png
    The gameObject with the "Boundary" tag is not effect by "Destroy()", but why is the object with the "Player" still effected by "Destroy()".
    Im asking because i tried by my self to give the bolt prefab a Tag called "Laser" to add points to an integer.
    I wrote something like if(other.tag =="Laser"){points++;}.
    And then neither the Laser nor the Asteroid was destroyed by their collision.
    But it works fine with the player tag if-statement.

    Does anybody know why?
     
  6. herman444

    herman444

    Joined:
    Oct 9, 2013
    Posts:
    3
    Hi All,

    I'm new to Unity myself & running through the Space Shooter tutorial.

    I've just started writing the player control script. Specified the Rigidbody as per the instructions, But don't get any movement. Is my code correct?

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

    stlouis4d

    Joined:
    Jul 19, 2015
    Posts:
    34
    With the addition of Unity 5 and mobile support to the Space Shooter tutorial, wouldn't it make sense to add a lesson on object pooling asteroids, enemy ships, lasers/bullets, and explosions to the Unity Learn Space Shooter tutorial? It would seem to be an obvious addition for mobile game development. Any plans from Unity to add this in the near future?

    I know that there's a separate Live Training lesson on Object Pooling, but implementing it directly into this project would provide a specific work case scenario to improve a beginner's understanding of its implementation in Unity.

    If not an "official" addition from Unity, any chance one of the more experienced users on this forum would be willing to post their commented code (with a tutorial if possible, but even without would be appreciated) for our reference here? If it was added directly to the example code provided with the Space Shooter tutorial, it would be an excellent learning tool.

    I think that something that specifically deals with implementing object pools in this type of game would be very beneficial, especially if it covered any issues that a beginner might need to be aware of like resetting an object's velocity and such when it's respawned from a pool, as well as how to "instantiate" (spawn) something from a pool and return it to the pool when it's "destroyed" (becomes inactive).

    I definitely see the need for something like this, if someone would be interested in providing this, I'm sure it would really be appreciated by the community.

    ******** EDIT

    Just to update my request, I dug a little deeper into this forum thread (which in and of itself was a LOT to sift through and digest), and found that my request had previously been answered by leoplureodon who had already done the work and posted a completed Space Shooter tutorial project that included updated code that utilizes object pooling. The project files can be downloaded and perused from either the original forum thread or this direct link.

    Thanks go out to @Leoplureodon for providing this. Great Unity community --- and very much appreciated!

    To note, while I've previewed the provided Unity project, I've not tested its effectiveness on a mobile device to verify if or how well it might work.
     
    Last edited: Dec 30, 2016
  8. Hoffes

    Hoffes

    Joined:
    Oct 21, 2016
    Posts:
    4
    You have to multiply with some speed.
    Code (Csharp):
    1.  
    2. public float speed; // declare in the Enginge and test it.
    3.  
    4. rb.velocity = movement * speed;
    5.  
     
    herman444 likes this.
  9. herman444

    herman444

    Joined:
    Oct 9, 2013
    Posts:
    3
    Hey Hoffes,

    Thanks for the reply. I got stuck on that bit of the tutorial. I have progressed to the end of the video, and the issues still persists.

    heres my code.
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. [System.Serializable]
    6.  
    7. public class Boundary
    8. {
    9.     public float xMin, xMax, zMin, zMax;
    10. }
    11.  
    12. public class PlayerController : MonoBehaviour
    13. {
    14.    
    15.     private Rigidbody rb;
    16.  
    17.     public float speed;
    18.     public float tilt;
    19.     public Boundary boundary;
    20.  
    21.     void Start()
    22.  
    23.     {
    24.         rb = GetComponent<Rigidbody>();
    25.     }
    26.  
    27.     void FixedUpadte ()
    28.  
    29.     {
    30.         float moveHorizontal = Input.GetAxis ("Horizontal");
    31.         float moveVertical = Input.GetAxis ("Vertical");
    32.  
    33.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    34.         rb.velocity = movement * speed;
    35.  
    36.         rb.position = new Vector3
    37.         (
    38.             Mathf.Clamp (rb.position.x, boundary.xMin, boundary.xMax),
    39.             0.0f,
    40.             Mathf.Clamp (rb.position.z, boundary.zMin, boundary.zMax)
    41.         );
    42.         rb.rotation = Quaternion.Euler (0.0f, 0.0f, rb.velocity.x * -tilt);
    43.     }
    44.  
    45. }
    Unfortunately when using the W,A,S,D keys. I still get no response from the space ship.
    Before you ask, the code is saved and working in other ways. I have the "Speed" & "Tilt" variables (Which we coded) visible.

    I've created a little video here to show everyone the issues. Let me know your thoughts. Or even if I have just gotten something wrong in the code.

    Everyones help is much appreciated.

    Cheers H
     
  10. Hoffes

    Hoffes

    Joined:
    Oct 21, 2016
    Posts:
    4
    Did you checked if it works with the normal dircetion buttons? Did you also checked if Horizontal and Vertical is set like here: Unbenannt.png
     
  11. jordifarreras

    jordifarreras

    Joined:
    Dec 31, 2016
    Posts:
    1
    Hello!

    I'm really new with this (programming and unity). However I've managed to get until the restart part of the tutorial.
    The code of the video is obsolete. I've found out a new code that should help. However, It doesn't work for me: when I press the "R" key, the game does not restart.

    Here is the code:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.SceneManagement;
    4.  
    5. public class GameController : MonoBehaviour
    6. {
    7.     public GameObject hazard;
    8.     public Vector3 spawnValues;
    9.     public int hazardCount;
    10.     public float spawnWait;
    11.     public float startWait;
    12.     public float waveWait;
    13.  
    14.     public GUIText scoreText;
    15.     public GUIText restartText;
    16.     public GUIText gameOverText;
    17.  
    18.     private bool gameOver;
    19.     private bool restart;
    20.  
    21.     private int score;
    22.  
    23.     void Start()
    24.     {
    25.         gameOver = false;
    26.         restart = false;
    27.  
    28.         score = 0;
    29.         UpdateScore ();
    30.         StartCoroutine (spawnWaves());
    31.     }
    32.  
    33.     void update ()
    34.     {
    35.         if (restart)
    36.         {
    37.             if (Input.GetKeyDown (KeyCode.R))
    38.             {
    39.                 SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
    40.             }
    41.         }
    42.     }
    43.  
    44.     IEnumerator spawnWaves()
    45.     {
    46.         yield return new WaitForSeconds (startWait);
    47.         while (true) {
    48.             for (int i = 0; i < hazardCount; i++) {
    49.                 Vector3 spawnPosition = new Vector3 (Random.Range (-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
    50.                 Quaternion spawnRotation = Quaternion.identity;
    51.                 Instantiate (hazard, spawnPosition, spawnRotation);
    52.                 yield return new WaitForSeconds (spawnWait);
    53.             }
    54.             yield return new WaitForSeconds (waveWait);
    55.        
    56.  
    57.             if (gameOver) {
    58.                 restartText.text = "Press 'R' to destroy more rocks";
    59.                 restart = true;
    60.                 break;
    61.             }
    62.         }
    63.     }
    64.  
    65.     public void AddScore (int newScoreValue)
    66.     {
    67.         score += newScoreValue;
    68.         UpdateScore ();
    69.     }
    70.  
    71.     void UpdateScore ()
    72.     {
    73.         scoreText.text = "Score: " + score;
    74.     }
    75.  
    76.     public void GameOver ()
    77.     {
    78.         gameOverText.text = "GAME OVER!";
    79.         gameOver = true;
    80.     }
    81. }
    82.  
    Thank you for your help!

    And have a happy new year by the way!
     
  12. herman444

    herman444

    Joined:
    Oct 9, 2013
    Posts:
    3
    Thanks again Hoffes.

    Yep just checked all looks good in there too... :S does my code look ok? I have created the first unity tutorial game no troubles using the same code...

    Spaceshooterinspector.jpg
     
  13. MuyangYan

    MuyangYan

    Joined:
    Sep 29, 2016
    Posts:
    2
    Hello,

    I am new to Unity and I'm using 5.4 to create this space shooter project. While working on shooting the shots, I discovered that even though the spaceship and the shot spawn empty game object were both set to origin, they had different z axes.

    upload_2017-1-1_11-1-47.png
    the shot spawn is set to origin,
    upload_2017-1-1_11-3-37.png
    the spaceship is set to origin,
    upload_2017-1-1_11-4-39.png

    upload_2017-1-1_11-5-20.png
    but the z axes are different.

    Does anyone know why this happens, and if so, how to fix it?
     
  14. mrobin604

    mrobin604

    Joined:
    Dec 17, 2016
    Posts:
    2
    Possibly you have one of the objects parented to something with a non-origin transform?
     
  15. mrobin604

    mrobin604

    Joined:
    Dec 17, 2016
    Posts:
    2
    I have the same code you do, and it works. The only thing I can think of that would cause this is that you are not calling GameOver() from the DestroyByContact script. Is the restart text being displayed when you die and the wave ends?
     
  16. MuyangYan

    MuyangYan

    Joined:
    Sep 29, 2016
    Posts:
    2
    I looked at the child bolt and It certainly was set to a different zed axes. I have reset its position and It now works. Thank you for your help.
     
    mrobin604 likes this.
  17. Near_O

    Near_O

    Joined:
    Jan 2, 2017
    Posts:
    1
    Hello sir, I am a beginner in Unity, and in your tutorial switch platforms to WebPlayer which cannot be found in my version (5.5.0f3) what should I do?
     
  18. Nahid_Unity

    Nahid_Unity

    Joined:
    Jan 4, 2017
    Posts:
    1
    HI ..
    I want to build my space shooter game using "PC, Mac & Linux Standalone " , but I am having problem with set a permanent ...
    Width:600 and Height: 900 ..screen regulation .
    so I want to know how to set screen regulation 600 by 900 on "PC, Mac & Linux Standalone " build setting ..
    please help me
     
  19. Mjau

    Mjau

    Joined:
    May 19, 2013
    Posts:
    2
    Hi everyone,
    I'm trying to do the space shooter tutorial but I can't seem to get past the movement.

    I've looked through this thread and tried a few of the fixes that are posted but nothing is happening.

    This is my code

    Code (CSharp):
    1. using System;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6.  
    7. public class PlayerController : Monobehaviour
    8. {
    9.     private Rigidbody rb;
    10.     public float speed;
    11.  
    12.     void Start ()
    13.     {
    14.         rb = GetComponent<Rigidbody> ();
    15.     }
    16.  
    17.        void FixedUpdate ()
    18.     {
    19.         float moveHorizontal = Input.GetAxis("Horizontal");
    20.         float moveVertical = Input.GetAxis("Vertical");
    21.         float moveForward = Input.GetAxis("Forward");
    22.  
    23.         Vector3 movement = new Vector3(moveHorizontal, moveVertical, moveForward);
    24.  
    25.         rb.velocity = movement * speed;
    26.     }
    27.  
    28. }
    I'm getting the following error:

    Assets/Scripts/PlayerController.cs(14,14): error CS0103: The name `GetComponent' does not exist in the current context

    Thanks in advance!
     
  20. LordJR

    LordJR

    Joined:
    Jan 10, 2017
    Posts:
    4
    It's been a long time since this post, but in case anyone else has this issue, which I did. Check that RigidBody is on the parent Bolt and not the child VFX. I had to remove it from the VFX where I created it initially, and then create it on the parent Bolt object. After do this, I was able to run the game and drag and drop the bolts and watch them go flying upwards, just like in the video.
     
  21. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    I'd say a restart of your machine and applications is in order as I can't see any reason for you getting that error.

    Now, I'm not sure what you're doing with float moveForward = Input.GetAxis("Forward"); but it's great you are experimenting!
     
  22. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    I'd say a restart of your machine and applications is in order as I can't see any reason for you getting that error.

    Now, I'm not sure what you're doing with float moveForward = Input.GetAxis("Forward"); but it's great you are experimenting!
     
  23. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    This is in "Player Settings". You can follow the same steps as in the video tutorial but change the target to PC, Mac & Linux Standalone and set the aspect ratio/screen size in the player settings window.
     
  24. Daftolddad

    Daftolddad

    Joined:
    Jan 12, 2017
    Posts:
    11
    Hi, Sadly i'm stuck at this point in the tutorial with exactly the same issue, have you managed to find out what the problem is or are you still waiting on a reply ?
     
  25. Giegre

    Giegre

    Joined:
    Mar 20, 2014
    Posts:
    1
    hi everyone

    I've been trying this tutorial recently
    I got stuck in creating the boundary for bolts

    my bolts shot fine when player object is stationary,
    but when i move my object forward and backward, my bolt got deleted immediately after instantiated



    here's my boundary code

    Code (CSharp):
    1. public class DestroyByBoundary : MonoBehaviour
    2. {
    3.     void OnTriggerExit(Collider other)
    4.     {
    5.         Destroy(other.gameObject);
    6.     }
    7. }

    my mover code

    Code (CSharp):
    1. public class Mover : MonoBehaviour
    2. {
    3.     private Rigidbody rb;
    4.     public float speed;
    5.  
    6.     void Start ()
    7.     {
    8.         rb = GetComponent<Rigidbody>();
    9.  
    10.         rb.velocity = transform.forward * speed;
    11.     }
    12. }

    and my player controller code

    Code (CSharp):
    1. [System.Serializable]
    2. public class Boundary
    3. {
    4.     public float xMin, xMax, zMin, zMax;
    5. }
    6.  
    7. public class PlayerController : MonoBehaviour
    8. {
    9.     private Rigidbody rb;
    10.     public float speed;
    11.     public float tilt;
    12.     public Boundary boundary;
    13.  
    14.     public GameObject shot;
    15.     public Transform shotSpawn;
    16.     public float fireRate;
    17.  
    18.     private float nextFire;
    19.  
    20.     void Start ()
    21.     {
    22.      rb = GetComponent<Rigidbody>();
    23.     }
    24.  
    25.     void Update ()
    26.     {
    27.         if (Input.GetButton("Fire1") && Time.time > nextFire)
    28.         {
    29.             nextFire = Time.time + fireRate;
    30.             Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
    31.         }
    32.     }
    33.  
    34.     void FixedUpdate ()
    35.     {
    36.         float moveHorizontal = Input.GetAxis ("Horizontal");
    37.         float moveVertical = Input.GetAxis ("Vertical");
    38.  
    39.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    40.  
    41.         rb.velocity = movement * speed;
    42.  
    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.  
    50.         rb.rotation = Quaternion.Euler (rb.velocity.z * (tilt/2.2f), 0.0f, rb.velocity.x * -tilt);
    51.     }
    52.  
    53. }
    what should I do?
     
  26. Alexei_UA

    Alexei_UA

    Joined:
    Dec 26, 2016
    Posts:
    6
    Can someone just give correct, working and complete code "PlayerController" for actual LATEST version of Unity (version 5.5) to avoid a lot of questions?
     
    Last edited: Jan 12, 2017
    Daftolddad likes this.
  27. Deleted User

    Deleted User

    Guest

    This tutorial has been updated for Unity 5; the player controller works as it is. Most of the errors people make are due to their lack of attention: misspelling, typos, pieces of code written within the wrong curly braces, and so on.

    Before posting here, make sure you didn't make any of those.

    Here is the Done_PlayerController script as it is in the "completed" folder:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. [System.Serializable]
    5. public class Done_Boundary
    6. {
    7.     public float xMin, xMax, zMin, zMax;
    8. }
    9.  
    10. public class Done_PlayerController : MonoBehaviour
    11. {
    12.     public float speed;
    13.     public float tilt;
    14.     public Done_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.             GetComponent<AudioSource>().Play ();
    29.         }
    30.     }
    31.  
    32.     void FixedUpdate ()
    33.     {
    34.         float moveHorizontal = Input.GetAxis ("Horizontal");
    35.         float moveVertical = Input.GetAxis ("Vertical");
    36.  
    37.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    38.         GetComponent<Rigidbody>().velocity = movement * speed;
    39.        
    40.         GetComponent<Rigidbody>().position = new Vector3
    41.         (
    42.             Mathf.Clamp (GetComponent<Rigidbody>().position.x, boundary.xMin, boundary.xMax),
    43.             0.0f,
    44.             Mathf.Clamp (GetComponent<Rigidbody>().position.z, boundary.zMin, boundary.zMax)
    45.         );
    46.        
    47.         GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, 0.0f, GetComponent<Rigidbody>().velocity.x * -tilt);
    48.     }
    49. }
     
    Last edited by a moderator: Jan 12, 2017
    Alexei_UA likes this.
  28. Daftolddad

    Daftolddad

    Joined:
    Jan 12, 2017
    Posts:
    11
    http://prntscr.com/dv3dxi
    Hi, sorry to keep banning on about this but, i'd just like an explination of what i have done wrong up to this point in the code (i have the completed code as well but i'm trying to understand what i've done wrong) if anyone can explain it i'd be grateful.
    Heres what i have so far (tried in mono and visual studio) the only thing i have noticed are the two errors in but i'm not sure if this is the issue or how to fix it if thats what the problem..



    http://prntscr.com/dv3dxi
    Again many thanks to anyone who can help.
     
  29. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    Looking at the screen shot I see you have Fixedupdate, it should be FixedUpdate, capitalize the U also. @ Golem 1900
     
    Daftolddad likes this.
  30. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    Giegre, don't know if you got your issue solved yet, but just a quick glance the code looks good. My guess is you have something incorrect in your hierarchy, possibly an incorrect parent child set up. The bolt object should move with your ship. You could try debugging it to see what object is destroying your bolt.
     
  31. Daftolddad

    Daftolddad

    Joined:
    Jan 12, 2017
    Posts:
    11
    Thanks, guess I couldn't see the wood for the trees, I'll make sure to change and test that when I get back from work. :)
     
  32. sk8lea

    sk8lea

    Joined:
    Jan 12, 2017
    Posts:
    4
    Hello! im having problems with the video 5 Moving the player
    Im also following the upgraded guide, but i am using the webGL because i couldnot find the web player, i wonder if it is messing arround.

    error:

    NullReferenceException: Object reference not set to an instance of an object
    PlayerController.FixedUpdate () (at Assets/Scripts/PlayerController.cs:36)

    the console shows the error here, in the boundary reference:
    Code (CSharp):
    1. rb.position = new Vector3
    2.             (
    3.                 Mathf.Clamp (rb.position.x, boundary.xMin, boundary.xMax),
    4.                 0.0f,
    5.                 Mathf.Clamp (rb.position.z, boundary.zMin, boundary.zMax)
    6.             );
    my code:playerController file
    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6.  
    7. public class Boundary
    8. {
    9.     public float xMin, xMax, zMin, zMax;
    10. }
    11.  
    12. public class PlayerController : MonoBehaviour {
    13.  
    14.     private Rigidbody rb;
    15.     public int speed;
    16.     public float tilt;
    17.     public Boundary boundary;
    18.  
    19.  
    20.     // Use this for initialization
    21.     void Start () {
    22.         rb = GetComponent<Rigidbody> ();
    23.  
    24.     }
    25.  
    26.     // Update is called once per frame
    27.     void FixedUpdate () {
    28.  
    29.         float moveHorizontal = Input.GetAxis ("Horizontal");
    30.         float moveVertical = Input.GetAxis ("Vertical");
    31.  
    32.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    33.         rb.velocity = movement * speed;
    34.  
    35.         rb.position = new Vector3
    36.             (
    37.                 Mathf.Clamp (rb.position.x, boundary.xMin, boundary.xMax),
    38.                 0.0f,
    39.                 Mathf.Clamp (rb.position.z, boundary.zMin, boundary.zMax)
    40.             );
    41.  
    42.         rb.rotation = Quaternion.Euler (0.0f, 0.0f, rb.velocity.x * -tilt);
    43.  
    44.  
    45.     }
    46. }
    thanks!
     
    Last edited: Jan 13, 2017
  33. Deleted User

    Deleted User

    Guest

  34. Mjau

    Mjau

    Joined:
    May 19, 2013
    Posts:
    2
    hahahaha yeah I don't know either :D, but yes I will try that, thank you!
     
  35. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    sk8lea, looking at your code, what I see missing is the line right before public class Boundary. You need to add
    [System.Serializable] so Unity knows to look for the Boundary class. I may be saying it wrong, but it is explained in the video. I think that is your issue.
     
    sk8lea likes this.
  36. Daftolddad

    Daftolddad

    Joined:
    Jan 12, 2017
    Posts:
    11
    Yes, you were right :) Thanks so much, it was getting a little discouraging to be honest, as i really couldn't see the error sometimes it really does need a second pair of eyes to point out the obvious, so it's nice to see some people are kind enough to spare a little time out of their day to look, and not just say "Check your code for errors yourself!" Sometimes you look so much you can't see the elephant in the room, so thanks again.
     
  37. sk8lea

    sk8lea

    Joined:
    Jan 12, 2017
    Posts:
    4
    It worked! thankyou very much my friend!
     
  38. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    Your welcome Golem1900 & sk8lea. I am just a beginner also, so I can feel the frustration at times.

    I am experiencing an issue that hopefully one of the Unity guru's can help me with. I am up to the point where I need to get the asteroid moving towards the player. In the video the instructions is to just drag the Mover script on to the asteroid and it works just like that. However on my game the asteroid looks like a curve ball thrown by a major league baseball pitcher. It goes a little ways then disappears.

    It is clear what is happening, the forward command is moving along the local axis of the asteroid, which is moving based on the RandomRotator script, until it hits the boundary which destroys it. I have confirmed this by Debug.Log(other.name) and observation that the amount of curve is different each time as well as watching the gizmo of the asteroid as I step through the game play.

    What I can't figure out is how to make it work li as shown in the video using the Mover script as is. I did get it to work by making a separate AsteroidMover script and changing the velocity from forward to new vector 3.

    Here are my three relevant scripts (Rotator, Mover and Asteroid Mover). Any input is greatly appreciated.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class RandomRotator : MonoBehaviour
    5. {
    6.     public float tumble;
    7.  
    8.     private Rigidbody rb;
    9.  
    10.     // Use this for initialization
    11.     void Start ()
    12.     {
    13.         rb = GetComponent<Rigidbody>();
    14.         rb.angularVelocity = Random.insideUnitSphere * tumble;  
    15.     }
    16.    
    17.    
    18. }
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Mover : MonoBehaviour
    5. {
    6.     public float speed;
    7.  
    8.     private Rigidbody rb;
    9.  
    10.     // Use this for initialization
    11.     void Start ()
    12.     {
    13.         rb = GetComponent<Rigidbody>();
    14.     }
    15.    
    16.     // Update is called once per frame
    17.     void Update ()
    18.     {
    19.         rb.velocity = transform.forward * speed;
    20.     }
    21. }
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class AsteroidMover : MonoBehaviour
    5. {
    6.     public float speed;
    7.  
    8.     private Rigidbody rb;
    9.  
    10.     // Use this for initialization
    11.     void Start()
    12.     {
    13.         rb = GetComponent<Rigidbody>();
    14.     }
    15.  
    16.     // Update is called once per frame
    17.     void Update()
    18.     {
    19.         rb.velocity = new Vector3(0.0f, 0.0f, speed);
    20.     }
    21.  
    22. }
     
  39. ItsPolk

    ItsPolk

    Joined:
    Jan 13, 2017
    Posts:
    1
    On, "Ending the Game" I'd like to note that the line you use to restart the game via pressing the "r" key is no longer valid with the new versions of Unity.
    Instead of: "Application.LoadLevel (Application.loadedLevel);"

    Use this: "SceneManager.LoadScene("Main", LoadSceneMode.Single);"
    without the quotations, and the "Main" mentioned should be the name of the scene you wish to load.
     
  40. Hai_Dang

    Hai_Dang

    Joined:
    Jan 14, 2017
    Posts:
    2
    I have some weird glitch with the lighting.
    When i start the game the lighting is completely normal.
    SS1sttime.png But when i restart it the lighting become darker.
    SS2ndtime.png
     
  41. Daftolddad

    Daftolddad

    Joined:
    Jan 12, 2017
    Posts:
    11
    Hi, forgive me if i'm wrong as i'm not even as far into the tutorial as you are at this moment, but in the Mover and AsteriodMover classes shouldn't it be using void FixedUpdate and not Void Update
    As per the scripting documentation?
    https://docs.unity3d.com/ScriptReference/MonoBehaviour.FixedUpdate.html

    As i said i might be wrong as i'm not this far into the tut as you but as it's dealing with a Rigidbody it kinda makes sence to me although i got the player mover script wrong earlier on so maybe i'm wrong here too :/

    Anyway hope this might help you out, i'll test it myself tomorrow as i'll have some spare time.
     
  42. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    You are awesome Golem1900.

    You gave me the clue I needed to figure out my issue.

    In the tutorial the instructor is putting the RigidBody command into the start method. This works because it is applying a one time force to the object and letting it coast. I put my statement in the update method, so it was applying the force once every frame, thus as the asteroid rotated, the force was applied in the new Z axis. It worked with the shots because there is no rotation being applied.

    All I had to do was move the one line to start, like it shows in the video and it works. No need for the additional asteroid mover script, though I may keep it that way just to experiment with.

    Thanks, Golem.
     
  43. Maltanis

    Maltanis

    Joined:
    Jan 14, 2017
    Posts:
    1
    Hi guys. I've been going through the Space Ship shooter and have just finished the Evasive Maneuvres script. I'm having an issue where my enemy ships are spawning, but not moving down the Z axis toward the bottom of the screen. I've checked my code, seems fine.
    Now when I disable the Evasive Maneuvers script, the Mover script works as normal. I narrowed this down and found that where I am setting the RigidBody position in the FixedUpdate method using the boundary, this seems to be causing my issue. But no idea why! When I comment out this line changing the position, it works!
    Can't figure this out, even with looking online already for anyone else having this issue. Any help would be great!

    Code (CSharp):
    1. using System.Collections;
    2. using UnityEngine;
    3.  
    4. public class EvasiveManeuver : MonoBehaviour {
    5.  
    6.     public float dodge;
    7.     public float smoothing;
    8.     public float tilt;
    9.  
    10.     public Vector2 startWait;
    11.     public Vector2 maneuverTime;
    12.     public Vector2 maneuverWait;
    13.  
    14.     public Done_Boundary boundary;
    15.  
    16.     private float currentSpeed;
    17.     private float targetManeuver;
    18.     private Rigidbody rb;
    19.  
    20.     void Start ()
    21.     {
    22.         rb = GetComponent <Rigidbody> ();
    23.         currentSpeed = rb.velocity.z;
    24.         StartCoroutine(Evade());
    25.     }
    26.  
    27.     IEnumerator Evade ()
    28.     {
    29.         yield return new WaitForSeconds(Random.Range(startWait.x, startWait.y));
    30.  
    31.         while (true)
    32.         {
    33.             targetManeuver = Random.Range(1, dodge) * -Mathf.Sign(transform.position.x);
    34.             yield return new WaitForSeconds(Random.Range(maneuverTime.x, maneuverTime.y));
    35.             targetManeuver = 0;
    36.             yield return new WaitForSeconds(Random.Range(maneuverWait.x, maneuverWait.y));
    37.         }
    38.     }
    39.    
    40.     void FixedUpdate ()
    41.     {
    42.         float newManeuver = Mathf.MoveTowards(rb.velocity.x, targetManeuver, Time.deltaTime * smoothing);
    43.         rb.velocity = new Vector3(newManeuver, 0.0f, currentSpeed);
    44.  
    45.         //where the Error is occuuring, commenting out this code makes the Enemy Ships move
    46.         rb.position = new Vector3
    47.         (
    48.             Mathf.Clamp(rb.position.x, boundary.xMin, boundary.xMax),
    49.             0.0f,
    50.             Mathf.Clamp(rb.position.z, boundary.zMin, boundary.zMax)
    51.         );
    52.  
    53.         rb.rotation = Quaternion.Euler(0.0f, 0.0f, rb.velocity.x * -tilt);
    54.     }
    55. }
    56.  
     
  44. fdd11

    fdd11

    Joined:
    Jan 10, 2017
    Posts:
    1
    Hi everyone, just finished the "Counting points and displaying the score" tutorial and I am struggling with one question,
    when we use

    GameObject gameControllerObject = GameObject.FindWithTag ("GameController");

    We are looking for GameObjects with the tag "GameController" in the scene and what I don't understand is how does it works? Asteroid as aprefab is not tagged as "GameController" the only GameObject tagged as "GameController" is GameController itself so, why does it works ? I know that GameController controlls the spawn of the asteroids but we never really pass the tag to the asteroids when we Instantiate them.
    sorry if my question is too silly.
     
  45. ReinoldJudd

    ReinoldJudd

    Joined:
    Jan 11, 2017
    Posts:
    7
    Having the same problem a lot of others have, but haven't yet found the solution...

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PlayerController : MonoBehaviour
    6. {
    7.     public float speed;
    8.  
    9.     private Rigidbody rb;
    10.  
    11.     void start ()
    12.     {
    13.         rb = GetComponent<Rigidbody> ();
    14.     }
    15.  
    16.     void FixedUpdate ()
    17.     {
    18.         float moveHorizontal = Input.GetAxis ("Horizontal");
    19.         float moveVertical = Input.GetAxis ("Vertical");
    20.  
    21.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    22.  
    23.         rb.velocity = (movement * speed);
    24.     }
    25.  
    26. }
    With that, I get "NullReferenceException: Object reference not set to an instance of an object"

    I'm completely clueless on what's missing here. Any help would be appreciated.
     
  46. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    ReinoldJudd, look at line 11 of your code. You have void start (). You need to capitalize the S. void Start ().

    The error is telling you that you didn't create (or instantiate) the object that you are referencing in line 23.
     
  47. Daftolddad

    Daftolddad

    Joined:
    Jan 12, 2017
    Posts:
    11
    No problem Ryeath:)

    @ReinoldJudd as Ryeath said you have to capitalize the S in void Start (I made a similar mistake myself :D) as for the other problem you just need to remove the () brackets you have put around the movement * speed and then i think you should be good to go.

    So line 23 should read as follows

    rb.velocity = movement * speed;
     
  48. Daftolddad

    Daftolddad

    Joined:
    Jan 12, 2017
    Posts:
    11
    Hmm ok so i just got to this point but i'm confused (Again)
    If i change the specified line to use "SceneManager.LoadScene("Main", LoadSceneMode.Single);"
    i get this error in the console http://prnt.sc/dwwggg
    But then when i try the method mentioned in the tutorial i get this http://prnt.sc/dwwi5b

    So my question is , Is Untity telling me to replace the "void Update" at the top of the code block with "public static void (LoadLevel)"
    Ideally if you could post up that part of your script it would help out an old fart trying to recapture some of his misspent youth out a lot :D (Still new to coding but my first computer was a Commodore64 (I was lazy back then just wanted to play games >.<))
     
  49. Tritize

    Tritize

    Joined:
    Jan 18, 2017
    Posts:
    8
    Hi,

    as some people I didnt get the web player, so went for web gl and had to install a module. Then i had the resolution problem and tried by adding a custom resolution for the game view.


    But, since i've install the module for building in web gl and web player (i've download both), I have some graphic issues that are just SO ANNOYING! like the background of my menu have dark flashes, when I open a menu the sub-menu is either highlighted in blue, either the wrinting is orange / invisible...
    Sometimes I open a menu and its just a black square.... I can't follow the tutorial anymore in thoses conditions! (plus the ceaseless flashes in the hierarchy / inspector background.... aaahhhh!!! I didnt read all the 42 pages of this thread but if someone can help me, had this issue or know how to fixe it... I think it's since I've download the module for web gl (downloaded 3 times already to see, from the unity menu in build settings..)...

    I was really lokking for learning unity through this tutorial and can't use it anymore, any help would be really appreciate, thanks and sorry if bad english.
     
  50. Tritize

    Tritize

    Joined:
    Jan 18, 2017
    Posts:
    8
    Arf i'm searching on the net for like an hour and I just find the solution by talking to a friend ..... ^^"

    For thoses who experiment that, if you're using a msi computer you have to exit the "Nahimic for MSI" thing and it work! So glad they put by default on computers useless things that you never use / ask for, but still paid and have to handle, yeay!
     
  51. victore82

    victore82

    Joined:
    Jan 19, 2017
    Posts:
    1
    Hi everyone,
    I am trying to figure out how to get the DestroyByBoundry script in C# working this is my current code:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class DestroyByBoundary : MonoBehaviour
    6. {
    7.     function OnTriggerExit (other : Collider) {
    8.         Destroy(other.gameObject);
    9.     }
    10. }
    Do I need to declare a GameObject with this code:
    public GameObject shot;
    and write Destroy(shot);
    any help would be greatly appreciated, thanks!