Search Unity

Space Shooter Tutorial Q&A

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

  1. valeriaC

    valeriaC

    Joined:
    Apr 8, 2014
    Posts:
    4
    Hello,
    I have a problem with the "Creating hazard"
    My asteroid does not appear on my screen game. I followed perfectly the tutorial, everything is the same but my asteroid does not appear .. Could someone help me please?
     
  2. fedeberg

    fedeberg

    Joined:
    Aug 7, 2015
    Posts:
    2
    Yes. The problem was that my Start method was written in lowercase. Thanks anyway!
     
    OboShape likes this.
  3. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Morning @valeriaC,
    firstly, when you play the game, in your scene hierarchy is the Boundary and Asteroid objects showing in your scene hierarchy? just to get a feel for where to start.
    if you disable the Boundary, does the asteroid show on screen? does it show in your scene hierarchy?
    Can you double check the tag on the Boundary is set. (and the tag is written in the same CaSe sensitivity in the editor as it is in the DestroyByContact script.)

    one other thing that I can think to check, have you unchecked use gravity on the Asteroids rigidbody component?
     
  4. Lord_Heman

    Lord_Heman

    Joined:
    Aug 16, 2015
    Posts:
    2
    Hello.
    There seems to be some logic in Unity / C# that I do not understand.
    We have the Mover script attached to an astroid.
    If I write the following code in the script:

    transform.position=new Vector3(0f,0f,-6f);
    spd=4;

    I would assume that the astroids (and ONLY the astroids, as the the astroids are the only objects that Mover is attached to) would start at the buttom at the screen, and moves towards the top.

    However the bolts now also starts at the buttom at the screen, and moves towards the top, with a speed of 4.
    I realize that this could be fixed by inserting the line:
    if (gameObject.CompareTag("Enemy"))
    above the code. But why is this necessary? The script (Mover) is not attached to bolt, and hence, bold should not by affected by it, or am I missing something here?
     
  5. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Afternoon,

    The Mover script is use by both the bolt and the asteroid to get movement in the Z plane.
    The speed value should not be set in the script itself, as this would give every gameobject this is attached to the same speed value.
    instead if you should just declare it as a public variable and not give it a value directly in the script.
    by declaring it as a public variable, you now have the ability to set the speed independently on each prefab this script is attached to (ie the bolt and the asteroid) via the inspector. so in your bolt prefab you can have the speed as 5 and the asteroid can have a -5 negative number, and both use the same generic script, but their speed values are stored in the prefab independently of each other.

    might be worth having another look over these two lessons to get another look at when the Mover script is used in the game.

    Creating Shots
    http://unity3d.com/learn/tutorials/projects/space-shooter/creating-shots?playlist=17147
    and
    Explosions (about 4 mins in)
    http://unity3d.com/learn/tutorials/projects/space-shooter/explosions?playlist=17147

    hope that helps a wee bit.

    ObO
     
    Last edited: Aug 16, 2015
    Lord_Heman likes this.
  6. walkerke06

    walkerke06

    Joined:
    Aug 15, 2015
    Posts:
    2
    Hi, I am currently on working on getting my ship to move. I have followed all the tutorials steps, and just added the PlayerController script, which compiles fine.

    Whenever I run my game, the ship just doesn't move! I am not getting any compiler errors and checked the names of the Input variables and everything seems to appear okay. Any ideas on what I might be missing here?

    I even tried setting the velocity of the ship to a constant, rather than taking in an input, and that does not seem to work either. Any help is appreciated!!
     
  7. winxalex

    winxalex

    Joined:
    Jun 29, 2014
    Posts:
    166
    Redoing tutorial in MVC,MVVM pattern by use of Rections(Observables)

     
    Yongho likes this.
  8. jongihong

    jongihong

    Joined:
    Aug 16, 2015
    Posts:
    4
    Hi I am new to Unity in general and I came upon this tutorial. It is very good and I would like to say that I learnt a lot from it. However whenever I try to build the game, I cannot shoot anymore. It has been bugging me and I cannot find a solution to this problem. Would anyone please give me help?
     
  9. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Evening @walkerke06,

    Sounds like you may have got your FixedUpdate() function in the PlayerController script in the wrong case.
    double check that the case is exactly as follows
    Code (CSharp):
    1. void FixedUpdate ()
     
  10. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    hi @jongihong,
    Just to clarify a couple of things, I may be totally wrong, but im trying to read into what you have stated.
    So you have your game within Unity, does the game run properly from within the Editor when you press the play button?

    Or, is it when you attempt to build the game for a specific target platform that the firing stops working?
    if so, what platform are you building to is it the 'PC Mac Linux Standalone'? Does the player move correctly and its just the firing thats not working?
     
  11. jongihong

    jongihong

    Joined:
    Aug 16, 2015
    Posts:
    4
    Just to answer your questions:
    1. It runs perfectly fine in the editor
    2. I tried building it on both web and windows and I can't shoot
    3. It is only the shooting the movement is fine
     
  12. walkerke06

    walkerke06

    Joined:
    Aug 15, 2015
    Posts:
    2
    That was it! I had it as fixedUpdate() instead of FixedUpdate().

    Thanks for the tip!
     
    OboShape likes this.
  13. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Wierd one, possibly Adam may have come across this in his travels.
    Just a couple of things to have a look at until he can get back to you.

    when you build for Standalone, you get the box for display preferences etc on startup (asuming you have this running as the default settings), theres an Input tab there, have a look on that to see if the Fire1 button is mapped correctly and to what buttons, then you can see if that buttons work if they are different.

    another thing to have a little look at just in case its a player issue.
    from the editor Edit > Project Settings > Player.
    under the resolution and presentations sections theres a checkbox for 'Use Player Log', tick that, build and run the standalone build of the game.
    one you have ran it, have a look in the Data folder next to your built .exe file for a text file called 'output_log.txt'.
    see if theres any glaring errors in that.

    other than that im not sure, might be just a case of resetting the inputmanager, but best wait for Adams response.

    Sorry Bud thats all I can think of myself :(

    ObO
     
  14. jongihong

    jongihong

    Joined:
    Aug 16, 2015
    Posts:
    4
    I was looking at the logs and i found this. I can't really understand it though
    (Filename: Line: 1715)

    Setting up 1 worker threads for Enlighten.
    Thread -> id: 2f0 -> priority: 1
    NullReferenceException
    at (wrapper managed-to-native) UnityEngine.Object:Internal_CloneSingle (UnityEngine.Object)

    at UnityEngine.Object.Instantiate[GameObject] (UnityEngine.GameObject original) [0x00000] in <filename unknown>:0

    at laser.Update () [0x00000] in <filename unknown>:0
     
  15. jongihong

    jongihong

    Joined:
    Aug 16, 2015
    Posts:
    4
    I managed to fix it. I just re-did the code on the tutorial and it worked! Thanks for the help though!
     
  16. Lord_Heman

    Lord_Heman

    Joined:
    Aug 16, 2015
    Posts:
    2
    Oooohh, I cannot beilive i missed that. Thanks alot!
     
    OboShape likes this.
  17. Yongho

    Yongho

    Joined:
    Aug 17, 2015
    Posts:
    4
    Hi.
    I have problem at DestroyByBoundary section.
    Boundary's setting are perfect.
    (isTrigger on, scale is good, has DestroyByBoundary script)

    problem is

    When I fire my shot, it disappears inside the boundary.
    So I checked using Debug.Log ("Trigger On :" + other.name).
    I found OnTriggerExit function called early than I expected!!
    My shot was disappeared inside the cube(boundary!!).

    I had triple checked function's name "OnTriggerExit".

    I enclosed zip file which is recorded problem situation.

    How can I fix my problem?

    ps : my platform setting is 'Android'. Does it make problem with OnTriggerExit?
     

    Attached Files:

    Last edited: Aug 17, 2015
  18. Kuroskira

    Kuroskira

    Joined:
    Aug 17, 2015
    Posts:
    3
    Hi.
    I have a problem with the Audio Source.
    I did exactly as the video and used the new code GetComponent<AudioSource>().Play (); but when i run the game the player explosion does not work.

    Any ideas on why is not working?
     
  19. bstout

    bstout

    Joined:
    Aug 23, 2013
    Posts:
    17
    Love the tutorial.
    I finally got to test play on my android phone using unity remote. But the movement was terrible.
    It was very hard to control the ship on the touch screen. Any suggestions on how to improve the movement?
     
  20. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Just wondering, check your bolt prefab, looks like you might still have the 'use gravity' box on the Rigidbody component checked?
    ensure it is unchecked and see if thats it.
     
    Yongho likes this.
  21. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    I take it that it's the explosion SFX thats not working?
    have you dragged the explosion_player sound file into the audiosource slot in the inspector? and that its set to play on awake.
     
  22. Kuroskira

    Kuroskira

    Joined:
    Aug 17, 2015
    Posts:
    3
    Yes i dragged it in the explosion_player sound set on awake by default but when I test it the player explosion is calculated as an asteroid explosion.

    I also just noticed that when the player is destroyed it increase the score value as hazards does but my player is tagged as 'Player' :s
     
    Last edited: Aug 17, 2015
  23. cotherman

    cotherman

    Joined:
    Aug 15, 2015
    Posts:
    2
    Question about a behavior. When adding the code to set the asteroids rotating:

    GetComponent<Rigidbody>().angularVelocity = Random...

    When I test the code the asteroid not only has angular velocity but linear as well and flies out of the bounding box. ????
     
  24. Yongho

    Yongho

    Joined:
    Aug 17, 2015
    Posts:
    4
    Oh. You're right! I remained that option. thank you!!
     
  25. cotherman

    cotherman

    Joined:
    Aug 15, 2015
    Posts:
    2
    Found the issue. I had two rigidbody components on the asteroid.
     
  26. tkn57

    tkn57

    Joined:
    Aug 19, 2015
    Posts:
    2
    Just completed the tutorial and everything works perfectly. There were a few minor issues which I managed to solve using common sense.

    Thanks for taking the time to create this.
     
  27. A_Sloane

    A_Sloane

    Joined:
    Aug 19, 2015
    Posts:
    10
    Hi,

    This is my first post on the forum so I hope I'm using the good options to answer to you.

    I experienced the same problem as you. There was no error in the code as the script came from the "done Playercontroller" script. But check that the name of the script is the same in the public class, i.e. PlayerController.

    Then, and this is the most important, once the script is done, do not forget to add the script component to the Player Game Object. And after, do not forget to fill the values in the component for the speed and the boundaries as it is shown in the video.

    It must fix the problem.

    Cheers !

    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.             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. }
     
  28. Kuroskira

    Kuroskira

    Joined:
    Aug 17, 2015
    Posts:
    3
    After hours of seeking I found my problem. It was in DestroyByContact i called the string "Player" with the lowercase 'p'.
     
    OboShape likes this.
  29. JoesPuff

    JoesPuff

    Joined:
    Aug 20, 2015
    Posts:
    2
    Where do I get the assets to download and import?
     
  30. Keygen91

    Keygen91

    Joined:
    Jun 10, 2015
    Posts:
    1
    hello got a problem ,,, when i shoot the shot stay in the position of it's spawn and don't go forward ,, how can i fix it ,, here the player script ...



    using UnityEngine;
    using System.Collections;

    [System.Serializable]
    public class Boundary
    {
    public float xMin, xMax, zMin, zMax;
    }


    public class PlayerController : MonoBehaviour
    {

    public float speed;
    public float tilt;
    public Boundary boundary;

    public GameObject shot;
    public GameObject shotSpawn;
    public float fireRate;

    private float nextFire;

    void Update ()
    {
    if (Input.GetButton("Fire1") && Time.time > nextFire)
    {
    shot = Instantiate(shot) as GameObject;
    nextFire = Time.time + fireRate;
    //GameObject clone =
    shot.transform.position = shotSpawn.transform.position;

    }
    }
    void FixedUpdate ()
    {

    float moveHorizontal = Input.GetAxis ("Horizontal");
    float moveVertical = Input.GetAxis ("Vertical");

    Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    GetComponent<Rigidbody>().velocity = movement * speed;

    GetComponent<Rigidbody>().position = new Vector3
    (
    Mathf.Clamp (GetComponent<Rigidbody>().position.x, boundary.xMin, boundary.xMax), 0.0f, Mathf.Clamp (GetComponent<Rigidbody>().position.z, boundary.zMin, boundary.zMax)
    );
    GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, 0.0f, GetComponent<Rigidbody>().velocity.x * -tilt);
    }

    }




    and this is the mover script of the shot ....


    using UnityEngine;
    using System.Collections;

    public class Mover : MonoBehaviour

    {
    public float speed;
    void Start ()
    {

    GetComponent<Rigidbody>().velocity = transform.forward*speed;


    }
    }
     
    Last edited: Aug 20, 2015
  31. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Apologies for not getting back sooner, offshore with limited tinterweb access on phone.
    For the assets. From within the editor.
    Window > asset store and search for space shooter. Or look for unity technologies publisher, and download then import
     
  32. wang2123125

    wang2123125

    Joined:
    Aug 7, 2015
    Posts:
    4
    sorry...
    Nonconvex Mesh Colliders and non-rigid motion in Unity 5.0 is no longer supported.
    The reason for this is that I did not add MESH BUG it?
    You will re-create the 5.0 version of Space Shooter tutorials?
    thank you very much
     
  33. wang2123125

    wang2123125

    Joined:
    Aug 7, 2015
    Posts:
    4
    Boundary between hello my meteorite will be automatically destroyed, wreckage borders will disappear after a meteorite, is that why?
    [Code = CSHARP] use UnityEngine;
    Use System.Collections; public class DestoryByBoundary: MonoBehaviour {void OnTriggerExit (Collider, etc.) {destroy (other.gameObject);}} [/ Code]
     
  34. KTreble

    KTreble

    Joined:
    Aug 21, 2015
    Posts:
    2
    Hi,

    Like everyone else im pretty new to Unity and im going through the tutorial videos and i'm on number 11 for the space shooter and i was just writing the script for the game controller and i have two issues which i can not fathom at all. I am using Unity 5.1.2f1.

    First is this massive block of text.

    UnassignedReferenceException: The variable hazard of GameController has not been assigned.
    You probably need to assign the hazard variable of the GameController script in the inspector.
    UnityEngine.Object.Internal_InstantiateSingle (UnityEngine.Object data, Vector3 pos, Quaternion rot) (at C:/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineObjectBindings.gen.cs:60)
    UnityEngine.Object.Instantiate (UnityEngine.Object original, Vector3 position, Quaternion rotation) (at C:/buildslave/unity/build/Runtime/Export/UnityEngineObject.cs:80)
    GameController.SpawnWaves () (at Assets/Scripts/GameController.cs:17)
    GameController.Start () (at Assets/Scripts/GameController.cs:10)

    I click on it in the console and the gamecontroller in the heirarchy goes yellow. Totally confused.

    secondly is this one

    Assets/Scripts/GameController.cs(16,39): error CS1525: Unexpected symbol `(', expecting `)', `,', `;', `[', or `='

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class GameController : MonoBehaviour
    5. {
    6.     public GameObject hazard;
    7.     public Vector3 spawnValues;
    8.  
    9.     void Start ()
    10.     {
    11.         SpawnWaves ();
    12.     }
    13.  
    14.     void SpawnWaves ()
    15.     {
    16.         Vector3 spawnPosition () = new Vector3 (Random.Range (-spawnValues.x spawnValues.x), spawnValues.y, spawnValues.z);
    17.         Quaternion spawnRotation = Quaternion.identity;
    18.         Instantiate(hazard, spawnPosition, spawnRotation);
    19.     }
    20. }
    21.  
    Any help would be appericated. Thanks
     
  35. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Double check your scripts for spelling and case sensitivity. Ensure for example you have Start() and not start() as one of the functions
     
  36. IanSmellis

    IanSmellis

    Joined:
    Nov 2, 2014
    Posts:
    26

    Not trying to be rude but the first error tells you what you need to do in the second sentence.
    The second issue I am not sure, but you end up changing the GameController script in the next lesson.

    **EDIT**
    I think you added () behind spawnPosition

    Code (CSharp):
    1.  Vector3 spawnPosition () = new Vector3 (Random.Range (-spawnValues.x spawnValues.x), spawnValues.y, spawnValues.z);
    Should be
    Code (CSharp):
    1.  Vector3 spawnPosition = new Vector3 (Random.Range (-spawnValues.x spawnValues.x), spawnValues.y, spawnValues.z);
     
  37. qqoopp0

    qqoopp0

    Joined:
    Aug 17, 2015
    Posts:
    7
    Dear Unity & my fellow Unity users,

    I have a question about the Prefabs.

    I finished the whole tutorial and followed all the steps.

    Now, I would like to change the "speed" of the hazard but it is in the Prefabs.

    I tried to read some threads related to that but no Luck I cannot understand and make the similar approach to complete it.

    Be more specific,

    we all have an IEnumerator SpawnWaves().
    Inside that, we have a while loop and then a for loop.
    I would like to increase the speed of the hazard after one for loop is completed.

    Is any one could give me some idea about this?

    I am sorry that I am still do not feeling very comforabtle to understand all the details in help :(
     
  38. StormShadow45

    StormShadow45

    Joined:
    Aug 22, 2015
    Posts:
    3
    Hi Everyone!

    I can't seem to move the Player in game mode. This happened in the Roll a Ball and in the Space Shooter Tutorail. I have copied the Script and it doesn't change anything. These ae the Errors:
    The referenced script on this Behaviour is missing! (twice)
    Assets/Scripts/SpaceshipMover.cs(8,17): error CS0103: The name `rb' does not exist in the current context

    Thanks in advance!
     
  39. Nuse

    Nuse

    Joined:
    Jun 24, 2015
    Posts:
    5
    I am having problems with the ship sticking to the boundaries and slowly moving past them if the directional button is continued to be pressed. Also to move away from the boundary takes some time as the ship unsticks itself out of the Boundary. I've scoured this thread and have not seen my problem. Here is my code and a screen shot of Unity: (Notice the z transform and the zMax in the Boundry)

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4.  
    5. [System.Serializable]
    6. public class Boundry
    7. {
    8.     public float xMin, xMax, zMin, zMax;
    9.  
    10. }
    11.  
    12. public class PlayerController : MonoBehaviour
    13. {
    14.  
    15.     public float speed;
    16.     public float tilt;
    17.     public Boundry boundry;
    18.  
    19.     private Rigidbody rb;
    20.  
    21.     void Start()
    22.     {
    23.         rb = GetComponent<Rigidbody>();
    24.  
    25.     }
    26.  
    27.     void FixedUpdate()
    28.     {
    29.  
    30.      
    31.         float moveHorizontal = Input.GetAxis("Horizontal");
    32.         float moveVertical = Input.GetAxis("Vertical");
    33.  
    34.         Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
    35.  
    36.         rb.AddForce(movement * speed);
    37.  
    38.         rb.position = new Vector3
    39.             (
    40.                 Mathf.Clamp(rb.position.x, boundry.xMin, boundry.xMax),
    41.                 0.0f,
    42.                 Mathf.Clamp(rb.position.z, boundry.zMin, boundry.zMax)
    43.             );
    44.  
    45.         rb.rotation = Quaternion.Euler(0.0f, 0.0f, rb.velocity.x * -tilt);
    46.  
    47.     }
    48.  
    49. }
    50.  
    Unity Boundry problem.jpg

    Any suggestions on were I went wrong?
     

    Attached Files:

    Last edited: Aug 23, 2015
  40. IanSmellis

    IanSmellis

    Joined:
    Nov 2, 2014
    Posts:
    26
    Mind posting the script?
     
  41. StormShadow45

    StormShadow45

    Joined:
    Aug 22, 2015
    Posts:
    3
    The Script is :
    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. public class NewBehaviourScript : MonoBehaviour
    10. {
    11.     public float speed;
    12.     public Boundary boundary;
    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.  
    21.             GetComponent<Rigidbody>().velocity = movement * speed;
    22.             GetComponent<Rigidbody>().position = new Vector3
    23.                 (
    24.                     Mathf.Clamp (GetComponent<Rigidbody>().position.x, boundary.xMin, boundary.xMax),
    25.                     0.0f,
    26.                     Mathf.Clamp (GetComponent<Rigidbody>().position.z, boundary.zMin, boundary.zMax)
    27.                     );
    28.     }
    29. }
    I have fixed all of the Problems exept the Behavior Error:

    The referenced script on this Behaviour is missing!

    witch comes up twice.

    Thank you for the attention and any help!
     
  42. IanSmellis

    IanSmellis

    Joined:
    Nov 2, 2014
    Posts:
    26
    Try changing
    Code (CSharp):
    1. public class NewBehaviourScript : MonoBehaviour
    to what ever the name of the script is, "NewBehaviourScript" needs to match the actual .cs file name.

    tell me how that works

    **EDIT**
    If that doesn't work try adding

    Code (CSharp):
    1. private Rigidbody rb;
    under
    Code (CSharp):
    1.     public float speed;
    2.     public Boundary boundary;
    Then add
    Code (CSharp):
    1.  void Start ()
    2.     {
    3.         rb = GetComponent<Rigidbody>();
    4.     }
    So it should look about like this
    Code (CSharp):
    1.     public float speed;
    2.     public Boundary boundary;
    3.  
    4.     private Rigidbody rb;
    5.  
    6.     void Start ()
    7.     {
    8.         rb = GetComponent<Rigidbody>();
    9.     }
     
    Last edited: Aug 23, 2015
    OboShape likes this.
  43. KTreble

    KTreble

    Joined:
    Aug 21, 2015
    Posts:
    2
    Thanks for your reply, i maybe should have posted a screen capture of the first issue as the gamecontroller had the hazard in the inspector. Just loaded up unity since the weekend and the error is gone.

    As for the other i actually get another error if i remove (). I'll just move on to the next lesson.
     
    IanSmellis likes this.
  44. IanSmellis

    IanSmellis

    Joined:
    Nov 2, 2014
    Posts:
    26
    That is quite strange. Let us know how things go.
     
  45. Kav_sub

    Kav_sub

    Joined:
    Jul 7, 2015
    Posts:
    2
    I'm currently at the part where you add movement to the ship. My code seems to be fine, yet the ship isn't moving when I hit play. I thought it might be an issue with the input settings, but I can't figure out what's wrong there. Here's the code so far:

    Code (CSharp):
    1. public class PlayerController : MonoBehaviour {
    2.  
    3.     private Rigidbody rb;
    4.  
    5.     // Use this for initialization
    6.     void Start () {
    7.         rb = GetComponent<Rigidbody>();
    8.     }
    9.    
    10.     // Update is called once per frame
    11.     void FixedUpdate () {
    12.         float moveHorizontal = Input.GetAxis ("Horizontal");
    13.         float moveVertical = Input.GetAxis ("Vertical");
    14.  
    15.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    16.         rb.velocity = movement;
    17.     }
    18. }
     
  46. Ifandbut

    Ifandbut

    Joined:
    Dec 1, 2010
    Posts:
    19
    Are the advanced tutorials for this posted anywhere? Like showing how to do a moving background, star field, enemies and AI? The first video said that there were more advanced sessions to cover these but I have not found any.
     
  47. IanSmellis

    IanSmellis

    Joined:
    Nov 2, 2014
    Posts:
    26
    You need a speed variable.
    add

    Code (CSharp):
    1. public float speed;
    to
    Code (CSharp):
    1. public class PlayerController : MonoBehaviour
    2. {
    3.  
    4.     public float speed;
    5.  
    6.     private Rigidbody rb;
    Then add
    Code (CSharp):
    1. * speed
    to
    Code (CSharp):
    1. rb.velocity = movement;
    Tell me if that works for you. or if you do not understand.
     
  48. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Morning @Ifandbut,

    The content that is included within the 'Done' folder is there for stretch goals for you to dissect yourself and learn from.
    There are no official extra tutorials for this content.
    if you look through it, and you find there is something that you want to know more about or have specific questions, then there is a scripting section within the Forum for any Scripting queries.
     
    IanSmellis likes this.
  49. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    I know its going to sound like a pain.
    but probably best to go through the tutorials again, but as well as checking your scripts, ensure that you have all the gameobjects and their respective components set up.
     
  50. R42

    R42

    Joined:
    Jun 27, 2015
    Posts:
    4
    Hello. I have a tiny problem with shooting bolts from the ship (part 7). I can drag and drop prefab and it works fine, but when I press fire, bolts stop in front of my ship and are static until I release the button. Afterwards they just float away through all axises. What could go wrong?
    report.png