Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Space Shooter Tutorial Q&A [ARCHIVED]

Discussion in 'Community Learning & Teaching' started by Valdier, Jan 12, 2014.

Thread Status:
Not open for further replies.
  1. GrapeApeGodzilla

    GrapeApeGodzilla

    Joined:
    Mar 20, 2015
    Posts:
    14
    Good morning. Was working with the mobile tutorial of space shooter and ran into a problem with the movement area and fire zone. When I pressed down on the image area for the movement, pressing outside the area, character still moves. Also, when I move and try to shoot in the fire zone and movement it stops shooting and forces my ship to move all the way to the right.
     
    Last edited: Mar 20, 2015
  2. DrReaper

    DrReaper

    Joined:
    Mar 16, 2015
    Posts:
    12
    Space Shooter build on Unity 5 - Chapter 14 - Counting Points.

    To display a score you have to build a GUI Text. On Unity 5 you make an empty game object. I am assuming that is (Ctrl + Shift + N) then select add component, select rendering, GUI Text. I type in the GUI Text text box and nothing is displayed in the game view. The example shows the text in the game window. I have been messing with this part for hours today and I don't see how to fix this.
     
  3. GrapeApeGodzilla

    GrapeApeGodzilla

    Joined:
    Mar 20, 2015
    Posts:
    14

    I was stuck like you as well on this when it came to creating the Score text, Game Over Text, and Restart Text when 4.6 came out. I looked at the the part in converting space shooter game to mobile which solved the issue goes in detail on creating the labels to use in unity 5 and code.

    You will be using the unity 5's UI for it.

    http://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/space-shooter-to-mobile

    Watch at 1:11:26 which shows you how to create the UI text. If you don't have a canvas on on game already, it will create a canvas once you select Create > UI > Text.
     
  4. KingfisherWyvernStudio

    KingfisherWyvernStudio

    Joined:
    Oct 5, 2011
    Posts:
    324
    @ DrReaper, like GrapeApeGodzilla already stated, the GUI has changed into UI with the introduction of Unity 4.6. The tutorials haven't been updated since, unfortunately, but luckily there were a lot of people who'd already done these kind of things.

    I haven't tried this in Unity 5 yet, but I assume it's pretty alike. Here's what I did to get the Score text, etc. into the game.

    More information about the new UI system can be found here. Good luck!

    /* wanders off to dive into Unity 3D UI Essentials and learn more from SimonDarksideJ */
     
  5. GrapeApeGodzilla

    GrapeApeGodzilla

    Joined:
    Mar 20, 2015
    Posts:
    14
    I tried putting the zones on different canvases, but still having same issue when it is not allowing me to move and shoot at the same time. Allows me to move, but when I go to shoot while moving it forces my ship to go to the right and doesn't allow it to fire.
     
  6. Tibbers

    Tibbers

    Joined:
    Mar 20, 2015
    Posts:
    5
    Hey all
    So i just picked up unity 5 and am going through all the tutorials, but i have just hit a road block that is confusing me now. I am on part 6 and just cant figure this out. I Keep getting the msg that

    Assets/Scripts/PlayerControler.cs(13,38): error CS1519: Unexpected symbol `boundary' in class, struct, or interface member declaration

    and

    Assets/Scripts/PlayerControler.cs(13,39): error CS1519: Unexpected symbol `;' in class, struct, or interface member declaration

    This this my first venture into scripting and i can see the rabbit hole is going to go deep.

    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 PlayerControler : MonoBehaviour
    11. {
    12.     public float speed;
    13.     public float Boundary boundary;
    14.  
    15.     void FixedUpdate ()
    16.     {
    17.         float moveHorizontal = Input.GetAxis ("Horizontal");
    18.         float moveVertiacal = Input.GetAxis ("Vertical");
    19.  
    20.         Vector3 movenent = new Vector3 (moveHorizontal, 0.0f, moveVertiacal);
    21.         GetComponent<Rigidbody>().velocity = (movenent * speed *Time.deltaTime);
    22.  
    23.         GetComponent<Rigidbody>().position = new Vector3
    24.             (
    25.             Mathf.Clamp(GetComponent<Rigidbody>().position.x, boundary.xMin, boundary.xMax),
    26.             0.0f,
    27.             Mathf.Clamp(GetComponent<Rigidbody>().position.z, boundary.zMin, boundary.zMax)
    28.             );
    29.     }
    30.  
    31. }
    32.  
    If any one knows what is going to that would be wonderful
    Best Tibbers
     
  7. Tibbers

    Tibbers

    Joined:
    Mar 20, 2015
    Posts:
    5
    Sorry I just figured it out i just needed more coffee :p

     
  8. MrConkin

    MrConkin

    Joined:
    Feb 11, 2013
    Posts:
    20
    Hey everyone, I've perused this thread and have yet to see anyone mention this, but can anyone point me to where I can download the assets for this tutorial? The tutorial itself directly links to a page on the Unity Asset Store, but the only link to download the assets I can find is a "Open in Unity" button, which opens Unity but does not download the assets.

    One of the comments on that page states...

    "The 'Open in Unity' button seems to do nothing; if this happens to you, just start up Unity and go to the Asset Store from within Unity. In the Asset store search for the Space Shooter project and then download and import."​

    However, I can't find a way to access the Asset Store from within Unity 5.0. Any help would be appreciated!
     
  9. MrConkin

    MrConkin

    Joined:
    Feb 11, 2013
    Posts:
    20
    Ah! Got it. So dumb. For anyone else who might run into the same issue, make sure that you've created a new project and can see the Unity editor. You cannot be sitting on the Unity 5 Projects/Get started screen. Then follow these instructions:

     
    Last edited: Mar 21, 2015
  10. Tibbers

    Tibbers

    Joined:
    Mar 20, 2015
    Posts:
    5
    I have the same issue as the_5th_ninja_turtle

    I have no Code errors

    Do the shots appear in the hierarchy at run-time?
    No,

    I had a look at the InputManager
    Fire1 is bound to joystick button 0 (This is the default ), I have tried setting this to, space, mouse 0,mouse 1,mouse 2 with no success
     
  11. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    I'll double check this. At one point there was a limitation in the way Windows OS worked that make naming the output difficult. Can't remember the details. I'm updating roll-a-ball to Unity 5. I'll run space shooter again and look for details that need to be annotated. I have annotated the GUIText issue, but I'll see if I need to annotate the build episode as well.
     
  12. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    This seems to be a bug in the way that the unity remote communicates with the new UI system. I'm tracking down the best workarounds. Currently this should only be a problem with the remote, and it should build fine to your device.
     
  13. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Double check that the transform for the GUIText element is set to (0.5, 0.5, 0.0)... Or anywhere between 0-1 in the x and y, so that it is in the viewport. It it's outside of that range, it won't be visible.
     
  14. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    This seems to be a bug in the way that the unity remote communicates with the new UI system. I'm tracking down the best workarounds. Currently this should only be a problem with the remote, and it should build fine to your device.
     
  15. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Heh! Coffee is always a help. Glad you got it working!
     
  16. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    First thing to check is: does the Done_ Main scene run? If so, we know that there isn't something terribly hinky going on, and we know it's limited to your scene.

    If you don't see the shots in your hierarchy, you can rule out, say, errors with the spawn code where the shots are spawning outside of the camera's frustum.

    No code errors... Hmmm...

    Is your "Instantiate" function being called?

    One way to test this is to put a debug line next to your "Instantiate" code and see if it shows in the console.

    Write:
    Code (csharp):
    1. Debug.Log("Instantiate called!");
    ... just before or just after your "Instantiate..." line in the same block of code.

    If you end up with this message in your console every time you fire, but you don't get a shot, the you need to check the "Instantiate" line.

    If you don't get the message, then you know your "Instantiate" is not being called and can look for an error in the code leading up to the "Instantiate" line. Perhaps some condition is not being met, and it's bypassing the "Instantiate" code.
     
  17. HeavyFuel

    HeavyFuel

    Joined:
    Mar 23, 2015
    Posts:
    4
    Hello there,

    Just finishing this tutorial. I just finished the Ending The Game video.
    All works well but one thing (I have Unity5 and have updated the rigidBody calls etc as well as used UI text with no issue).
    When Player is killed and I press the 'R' button after the Restart text appears, I can start again no problem BUT the background is gone. It is black now.

    Has this happened to anyone before? Is it maybe in this line in the GameController.cs?

    Code (CSharp):
    1.     void Update ()
    2.     {
    3.         if (restart)
    4.         {
    5.             if (Input.GetKeyDown (KeyCode.R))
    6.             {
    7.                 Application.LoadLevel(Application.loadedLevel);
    8.             }
    9.         }
    10.  
    11.     }
     
  18. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    o_O? Is this consistent? In the editor and deployed? Have you restarted unity and tried again? Any errors?
     
  19. HeavyFuel

    HeavyFuel

    Joined:
    Mar 23, 2015
    Posts:
    4
    Hi this is in the Editor. I have restarted Unity and I have the same problem. I'll try to do a build on webplayer and see what happens.
     
  20. HeavyFuel

    HeavyFuel

    Joined:
    Mar 23, 2015
    Posts:
    4
    I have done a web build and it works fine. It is only happening in the editor. :/

    any reasons for this?
     
  21. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Fuss ifino... And you've done a full restart on both machine and unity? If so and it persists, you can file a bug report with that project attached, send me the number and I'll look at your project.
     
  22. SlugPup

    SlugPup

    Joined:
    Mar 5, 2015
    Posts:
    1
    Hey, I have what I'm hoping is a pretty simple problem:

    I just completed "Creating shots" and my shots move, but they don't move smoothly like they do in the video. Instead, they have a sort of stuttering (though constant) motion. It looks almost as if the shots are moving in units of the shot's length, rather than in a continuous, fluid motion.
     
  23. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    @ryan42 had the same problem in these posts:
    http://forum.unity3d.com/threads/space-shooter-tutorial-q-a.222119/page-9#post-2023573

    He didn't say what the problem is.

    Can you compare your prefab to the done prefab and see if you can find the difference? Then post the answer here?
     
  24. GrapeApeGodzilla

    GrapeApeGodzilla

    Joined:
    Mar 20, 2015
    Posts:
    14
    Thank you very much for the reply. I am going to try to upload it on my iPad after following the iOS dev manual on the site. Hopefully it will work! :)
     
  25. GrapeApeGodzilla

    GrapeApeGodzilla

    Joined:
    Mar 20, 2015
    Posts:
    14
    It works fine on the iPad once I deployed it following the guide deploying to iOS. Thank you for the help!
     
  26. HeavyFuel

    HeavyFuel

    Joined:
    Mar 23, 2015
    Posts:
    4
    Hi Adam thanks. Bug submitted.
    Case 683277. Let me know if you can reproduce it!

    cheers.
     
  27. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Ok. There are a couple of issues that primarily relate to the new lighting system.

    The first thing is that the Nebula background needs to be changed to "Unlit/Texture".
    Screenshot 2015-03-25 14.26.27.png

    IIRC, this was a step in the tutorial? (Let me know if I'm wrong...)

    One note, your material took an auto-generated name off of the texture: "tile_nebula_green_dff", this should probably be renamed "tile_nebula_green_mat" for consistency's sake. Feel free, however, to keep to whatever naming convention you prefer.

    The second issue seems to be related to ambient light and they skybox. In Unity5, our new scenes come with a default skybox and ambient light set to the default skybox:
    Screenshot 2015-03-25 14.48.35.png

    To solve the lighting issue, remove the default skybox and leave "none":
    Screenshot 2015-03-25 14.49.51.png

    I don't have an explanation as to why this is affecting the lighting, but this is my best current workaround.
     
    HeavyFuel likes this.
  28. Jeriko2k3

    Jeriko2k3

    Joined:
    Mar 18, 2015
    Posts:
    28
    Just started and I am looking for a shortcut in the script so I don't have to keep typing " GetComponent<Rigidbody>() " over and over again, I tried looking at the roll-a-ball again to see about duplicating this option, but keep getting error messages.

    Thanks.
     
  29. kameranis

    kameranis

    Joined:
    Mar 25, 2015
    Posts:
    1
    First up, great tutorial. I am learning Unity for a class in my university and this tutorial will cover much of the stuff we would do in the pc lab.

    Secondly, will you be uploading a tutorial to get from this to the done_ version pf the game?
     
  30. Jeriko2k3

    Jeriko2k3

    Joined:
    Mar 18, 2015
    Posts:
    28
    I blocked out what I have tried so not to stop the program, wanted to see if I was on right track

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PlayerCtrl : MonoBehaviour
    5.  
    6.  
    7.     {
    8.  
    9.     public float speed;
    10.  
    11.         void FixedUpdate ()
    12.        
    13.            
    14.  
    15.         {
    16.  
    17.             float moveHorizontal = Input.GetAxis ("Horizontal");
    18.             float moveVertical = Input.GetAxis ("Vertical");
    19.  
    20.             Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    21.             GetComponent<Rigidbody> ().velocity = movement * speed;
    22.             //Ship.velocity = movement * speed;
    23.            
    24.         }
    25.     //void Ship ()
    26.     //{
    27.     //    GetComponent<Rigidbody>();
    28.     //}
    29.     }
     
  31. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    In the definition:

    Code (csharp):
    1. private Rigidbody rb;
    ... and in Start ():

    Code (csharp):
    1. rb = GetComponent<Rigidbody>();
    ... then you can use:

    Code (csharp):
    1. rb.velocity = ...

    This is what was being done under the hood in previous versions.
     
  32. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Thanks! That's good to hear! I trust our material will help!

    Sadly, we won't be releasing tutorials for the additional material in the "done" section. These are stretch goals for the student to achieve, and the done material is there for help and guidance.
     
  33. meteoros

    meteoros

    Joined:
    Mar 19, 2015
    Posts:
    15
    hi,i tried to add a new GUIText called "RestartText",but when i go to for example x position and try to change it another GUIText i've made before called "Score Text" is the one affected for my x position changes,any ideias how to solve it? check this:
     
    Last edited: Mar 25, 2015
  34. doctorhr2

    doctorhr2

    Joined:
    Mar 25, 2015
    Posts:
    4
    I just had this problem too and I realised that I had attached a Rigidbody to the 'Vfx' child AND the 'Bolt' parent. I deleted the one on the 'Vfx' child and it shot smoothly up the screen. It was probably the engine trying to cope with two instances of Rigidbody on one object that was causing the lag?
     
    SlugPup likes this.
  35. Jeriko2k3

    Jeriko2k3

    Joined:
    Mar 18, 2015
    Posts:
    28
    Thanks for the earlier answer Adam, didn't figure it out and just went with the full code. I'll work on shortcuts when I get better.

    My new question is related to the Shot Spawn Child object. I created a Empty object and made it a child of the player, however the video at about 4 minutes in shows that you can grab the shot spawn and place it in front of the ship. I do not see this on my screen, I have tried moving the z axis but still do not see anything that I can use to further the program. Is this something new with Unity 5 or did I miss something.
     
  36. Jeriko2k3

    Jeriko2k3

    Joined:
    Mar 18, 2015
    Posts:
    28
    upload_2015-3-25_20-32-42.png I guess it is correct now, showed up after I walked away as a circle. But now both the player and engine names are in blue print? Not sure what I did.
     
  37. GrapeApeGodzilla

    GrapeApeGodzilla

    Joined:
    Mar 20, 2015
    Posts:
    14
    The engines names are going to be in blue print if you created or used the prefab version. Also, you might've placed player in a prefab. Or, they're in blue because they are parents that have objects inside of them.
     
    Jeriko2k3 likes this.
  38. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    This could be. It could be something like the script is adding force to one of the rigidbodies and the other is causing drag, but then gaining velocity from the connection ??? Not sure how they are interacting, but you should only have one rigid body per GameObject family.
     
  39. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Just be aware that the "GetComponent" look up does take more time than using a reference, so it's always best to cache the reference in a variable as I show above.

    Glad you got that working.
     
  40. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    The reason you see the gizmo as a circle, is you've selected the "Transform Rotate" tool:
    Rotation-Example.png

    If you want to move the GameObject with the pointer, you need to change to the Translate tool:
    Translate-Tool.png

    This will change the gizmo from a sphere (tho' in this image, it's straight down on the sphere, so it's compressed into a circle) used to Rotate the GameObject's Transform component, into the 3 arrows gizmo used to Translate the GameObject's Transform component.
     
  41. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Yes, the type being in blue indicates that the GameObject is a prefab. The only confusing issue can come from dragging a model into the scene, which is (from Unity's point of view) a prefab, but not one that you've made, nor is saved specifically in the project's Asset's directory.
     
    Jeriko2k3 likes this.
  42. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
Thread Status:
Not open for further replies.