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. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Cool! Let us know how you get on!
     
  2. Nightgaunt

    Nightgaunt

    Joined:
    Jan 15, 2014
    Posts:
    7
    I "finished" it yesterday, but now I'm pondering whether I should continue adding to this or doing another tutorial (either the stealth one or the survival shooter), I don't know which would benefit me more in terms of learning.

    Things I thought I could add to this:
    *Somehow make the asteroids appear in different sizes
    *If asteroids could be scaled upwards, like from 1 to 5 where 1 is the regular size now, make every size thereafter take one more hit to destroy, so a "2-asteroid" would take 2 hits, a "3-asteroid" 3 and so on. This should of course affect the scoring as well, with bigger asteroids giving more points.

    Do you have any pointers how I could achieve this, or is it even possible? I read up on scaling gameobjects, so I'm thinking it's something I need to add to the GameController script, where the hazards are spawned? Am I on the right track here?

    Edit: Also, FWIW I noticed that the enemy explosion sound is different in the Done_Enemy Ship than the one you get in the Audio folder. As in, eplosion_enemy != done_explosion_enemy.
     
  3. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Either or those additional projects will be helpful.

    FWIW: Nightmares will be a quicker, smaller project than Stealth. You will probably learn more from Stealth. I would do Nightmares next and then do Stealth.

    But: Augmenting Space Shooter first might not be a bad idea at all.

    All of your suggested additions are great ideas.

    You are on the correct track. When you spawn the asteroid, you want to set its scale. You will need a reference to the GameObject you spawn:
    Code (csharp):
    1. GameObject newHazard = Instantiate (... code...) as GameObject; // see instantiate documentation!
    2. float scaleValue = Random.Range (1.0f, 4.0f);
    3. newHazard.transform.localScale = new Vector3.one * scaleValue;
    This code will make smoothly variable sizes from 1-4. If you want them in discreet, quantised sizes, look into using random ints, rather than floats. For Vector3.one see: http://docs.unity3d.com/ScriptReference/Vector3-one.html
     
  4. Nightgaunt

    Nightgaunt

    Joined:
    Jan 15, 2014
    Posts:
    7
    What does the "as GameObject" thing do on the first line? And should this line replace something or should I add it as a new line inside the for loop? I tried writing the code but Unity gives me an error, "unexpected symbol 'scaleValue'", have no idea what that one means. Also, should scaleValue be public or private? And where should I put it, in the beginning of the code or...?

    This is how it looks right now, it's a bit long so I thought I'd put it behind spoilers.
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class GameController : MonoBehaviour
    6. {
    7.    public GameObject[] hazards;
    8.    public Vector3 spawnValues;
    9.    public int hazardCount;
    10.    public float spawnWait;
    11.    public float startWait;
    12.    public float waveWait;
    13.    public float scaleValue = Random.Range (1.0f, 4.0f);
    14.    
    15.    public GUIText scoreText;
    16.    public GUIText restartText;
    17.    public GUIText gameOverText;
    18.    
    19.    private bool gameOver;
    20.    private bool restart;
    21.    private int score;
    22.    
    23.    void Start ()
    24.    {
    25.      gameOver = false;
    26.      restart = false;
    27.      gameOverText.text = "";
    28.      score = 0;
    29.      UpdateScore ();
    30.      StartCoroutine (SpawnWaves ());
    31.    }
    32.    
    33.    void Update ()
    34.    {
    35.      if (restart)
    36.      {
    37.        Application.LoadLevel ("Menu");
    38.      }
    39.    }
    40.    
    41.    IEnumerator SpawnWaves ()
    42.    {
    43.      yield return new WaitForSeconds (startWait);
    44.      while (true)
    45.      {
    46.        for (int i = 0; i < hazardCount; i++)
    47.        {
    48.          GameObject hazard = hazards [Random.Range (0, hazards.Length)];
    49.          Vector3 spawnPosition = new Vector3 (Random.Range (-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
    50.          Quaternion spawnRotation = Quaternion.identity;
    51.          GameObject newHazard = Instantiate (hazard, spawnPosition, spawnRotation) as GameObject;
    52.          newHazard.transform.localScale = new Vector3.one * scaleValue;
    53.          yield return new WaitForSeconds (spawnWait);
    54.        }
    55.        yield return new WaitForSeconds (waveWait);
    56.        
    57.        if (gameOver)
    58.        {
    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. }
     
  5. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    This is a great start! You're making logical connections and asking the right questions.

    Your code probably won't work the way you expect it to (I expect).

    Let's look at the declaration first:
    Code (csharp):
    1.  public float scaleValue = Random.Range (1.0f, 4.0f);
    This will create the variable "scaleValue" when you run this script, but, by assigning the value at the time of declaration, you will set the scaleValue for the game as one single value for the entire game.

    When declaring a variable, unless you need a starting value, simply declare it and leave it alone:
    Code (csharp):
    1.  public float scaleValue;
    Also, realize that if this is a public variable you will be able to set the starting value in the inspector, so this step of initializing and setting the value of a variable is not strictly necessary when coding in Unity.

    So, now that we have removed the value from scaleValue, we need to set it later in our code. We want this to create a new random value each time we create a new hazard, so, just before setting the local scale (inside the Spawn Loop, after the instantiate line), we need to get a random value to set.

    Remember our variable is a "box" or "container" to hold a value, and the contents can change, so we can reuse this variable.
    Code (csharp):
    1. scaleValue = Random.Range (1.0f, 4.0f);
    Now, each time the loop is run, Random.Range will create a new value between 1.0 and 4.0 (inclusive) and assign it to scaleValue.

    All this being said (as I wanted to make the point about declaring variables), I think the best way to do it is the way I wrote it in my original example.

    There is a concept called scope, which is essentially: "Who knows about, and who can use, an item we have declared in our code?"

    Essentially, the only part of our code that needs to know about scaleValue is the instantiate part of the spawn loop. We, as the developers of the game, don't need to know about it, as we don't need to see it or set it in the inspector - so therefore it does not need to be a public variable declared at the top/root of our script. Moreover, because it is only needed within a loop inside a function/coroutine, we don't even need it as a private variable at the top/root of our script.

    Simply declare the variable just before you use it (see my example above) in the spawn loop coroutine:
    Code (csharp):
    1. float scaleValue = Random.Range (1.0f, 4.0f);
    By starting with the type (eg: float) you are telling C# and Unity that you are declaring a new variable. This variable stays within the scope of the coroutine and no one outside of it is bothered by it, can access, use or change it. <-- All this is very good for making safe, maintainable code.

    [The error you received on this line was probably due to a typo or other error ...]

    "What does the 'as GameObject' do on the first line?"

    This is "casting". I don't have any good links about casting to hand, but - what you are doing is telling Unity what type of generic object you have instantiated. If you look at the documentation on Instantiate, you can see that what is being instantiated is an "object", but the type of this object has not been set. This gives you as the developer the freedom to instantiate any type of object you want (rigidbody, transform, gameobject), but to effectively use this object, Unity needs to know what type of object it is, so you must tell Unity what you have instantiated - in this case a "GameObject". (Now there are two ways to cast the type, by starting the line with: (Type) or, as in this case, ending the line with as Type (where Type is the Type of Object you want to cast to) but you will have to do your own research into the differences today!)

    The reason we need to do this (the casting) is that we need a reference to the specific item we have just instantiated to be able to affect it in any way. If we didn't have a reference, it's a bit like going to a car parking lot and asking the attendant "Please, can you wash my car?" and walking away. The attendant is going to look at you, look at the 100's of cars in the lot and shake his head. "WTF? Which car?" This "Which car?" will often be an error in your game, like "NullReferenceException" - your game is saying the reference is "null" or doesn't exists. And when getting a reference to an object, we need to know what Type that object is, so we can deal with it correctly.
    Code (csharp):
    1. SportsCar myCar = GetCarInParkingLot (myTicketNumber) as SportsCar;
    2. PleaseWash (myCar);
    So, we are taking a reference by creating a variable GameObject newHazard. Then we assign that newHazard to the object returned by the instantiate function - which we have cast as a GameObject, so that it fits inside the GameObject variable we have just declared.

    Now that we have our reference (as a variable) to the new Hazard, we can "Do Something" to it, like change its local scale!

    So - that's changing the transform's local scale.

    Does this make sense?

    -

    Now, here's some homework:

    This code will not only change the size of the asteroids, but - because we instantiate the enemy ships with the same co-routine - it will also change the size of the enemy ships.

    How do you prevent that from happening?
     
  6. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    In response to a question about Input.GetAxis:

    Input.GetAxis should work for Keyboard and Mouse, Joysticks and Controllers.

    Essentially, the InputManager is monitoring an "axis", and this can be a set of keys (A&D, S&W), an axis on a controller (x-axis, y-axis), so you don't have to worry about the input device.

    Also be aware that you can assign the same axis name multiple times to cover multiple input devices on the same axis:

    Go to Edit>Project Settings>Input to show the input manager in the inspector.

    Note how "Horizontal" is declared twice; once as a Key or Mouse Button and once as a Joystick Axis

     
  7. Nightgaunt

    Nightgaunt

    Joined:
    Jan 15, 2014
    Posts:
    7
    Thank you, your post was very enlightening. I think I know how to do this now, but sadly I have to go to school today so I won't be able to test it today. As for the homework part, I probably need to play around with the tags? And then insert the scaling in an if-loop, where everything enemy-thing EXCEPT enemy-ship is resized. All in all, I think I can handle this now and am eager to try it out properly.

    I'll post an update once I'm done.
     
  8. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Looking forward to the update.

    Like all things code, there are many ways to skin that digital cat. Your way is a good one.

    Be aware somewherein the back of your mind that comparing one string to another is not the most inexpensive process. That being said, in a project this size, one pretty much any device, comparing one or two tags every few frames will be invisible. There are other ways to do this when you get into more complicated subjects. If you run "Stealth" the project will get into Hash IDs, which is more efficient (tho' arguably even unnecessary in a project that size). Hash IDs have other advantages, including less of a chance of an accidental typo slipping through... ... but I digress.

    Keep up the good work and report back from the front.
     
  9. Nightgaunt

    Nightgaunt

    Joined:
    Jan 15, 2014
    Posts:
    7
    Hahaha, I can't believe I got it working! I had to fiddle with it for an hour or so, but now it works like I wanted it to. And, it doesn't scale the enemy ships, just the asteroids.

    I had loads of trouble at first - all asteroids spawned in the same place and wouldn't move, until another one spawned on-top of an existing one, after which they flew away in crazy directions. I had the biggest trouble to find out what was wrong, until I simply re-checked all the values I'd entered: tumble: 0, movement speed: 0. Yeah? Not surprising they weren't moving at all.

    Then the scaleValue drove me nuts. It gave the same error as described in my bigger post (with the code pasted), and would pester me about "error CS1525: Unexpected symbol `scaleValue', expecting `(', `)', `,', `;', `[', `{', or `<operator>' "

    I was like yeah, what's wrong with this line, I done it over and over surely ten times, and to no avail. I was sure there were no typos, and there wasn't - the solution was as simple as changing this line

    newHazard.transform.localScale = new Vector3.one * scaleValue;

    to this

    newHazard.transform.localScale = new Vector3(1,1,1) * scaleValue;

    Don't ask me why the former doesn't work, for that I have no answer, but I can testify that the latter indeed DOES work. After I got it working, I still had other problems, like no enemy ships spawning, but loads of different sized asteroids. Turns out my lines of code were in the wrong order, or rather, I had put too many lines inside the loop that checks whether the spawned hazard was an asteroid or not. Oh well.

    Now I only have two more things I'd like to add to this, then I'd call it complete and move on to the next tutorial, and that is
    a) award the player a higher score for destroying bigger asteroids, and make so that they have more health, ie. they'd take more hits. Not really sure how to do this off the bat... and
    b) a local leaderboard. Now, I read up on this in the scripting manual, and there was this reference to SocialPlatforms leaderboard, but I don't know if that's the way to go or not, or if there's another way. All I really want is a top-5 or -10, where the player can, if he makes it on the list, put his name after the score. Then I'd obviously make a new button in the menu from where you can check the highscores, also.
     
  10. shadbags

    shadbags

    Joined:
    Jul 14, 2014
    Posts:
    5
    So I got suddenly stuck on Chapter 6 - Creating shots.

    I got through everything, but suddenly when I go to test, my bullets don't move.

    The Done_Bolt prefab works correctly. Mine does not.

    As far as I can tell, the inspector is identical. The code between mover and done_mover are identical. It's as if speed is 0 (It's set to 20 in the prefab. Even tried changing it and reapplying it, as well as hardcoding the 20 into the multiplication. Both don't work.)

    Edit: Apparently void start() is different to void Start(). Goddamn it.

    Edit2: And I'm finished! First ever game done in Unity. Thanks very much for the tutorial! Little bit fundamental in patches (I caught myself writing for loops and filling in stuff before you got to it) but I totally understand why.
     
    Last edited: Sep 26, 2014
  11. Mr Justice

    Mr Justice

    Joined:
    Sep 27, 2014
    Posts:
    1
    Thanks for this tutorial it was really appreciated. I'm trying to figure out how to take it further. More asteroids from other directions, enemy ships (having the fire or strafe would be great), health bar, moving starfield would all be great. I've been looking around and I can find plenty of tutorials but I'm lost on how to insert them into the code generated by the tutorial. I'm hoping someone might be able to point me in the the right direction. I am a complete beginner to Unity so please be gentle.
     
  12. ctdaudio

    ctdaudio

    Joined:
    Oct 4, 2014
    Posts:
    4
    Hi there. Complete rookie with 0 code experience and have done surprisingly well so far with the tutorial. It really is great. However I've got stuck on the shooting shots tutorial. My scripts seem to be exactly what's on the video and the inspector looks fine, but I physically can't shoot anything?! Here are some screenshots...

    Capture.PNG Capture2.PNG
     
  13. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    see your update function.
    change it to Update() rather than update() as the 'U' is case sensitive.
     
  14. ctdaudio

    ctdaudio

    Joined:
    Oct 4, 2014
    Posts:
    4
    Thanks. All working great now! :D
     
  15. kunkka

    kunkka

    Joined:
    Sep 5, 2013
    Posts:
    4
    Hello, I have 2 small questions about our game :D.

    1. How can I make an Asteroid explode into 5 small asteroid and they fly away from the center of the asteroid.
    2. How can I make an Enemy explode after it got hit by bullets and the stars are instantiate after the Enemy exploded floating around the screen.

    Thank you and sorry for my bad English :(, have a nice day :D.
     
  16. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    You all ready have most of the tools you already need, by working through the shooter tutorial.

    in your destroyByContact on the main asteroid, when the asteroid is destroyed you can use a loop to instantiate 5 smal asteroids. just make a new small asteroid prefab much like the larger one, but instead of giving it just a velocity in the -Z make it a random Z and X velocity. and instantiate from the transform position of the large asteroid that u destroyed.
    see how u get on :)

    im not at home just now so cant do a sample sorry.
     
  17. kunkka

    kunkka

    Joined:
    Sep 5, 2013
    Posts:
    4
    I got it now, thank you so much :) :) :)
     
  18. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    good stuff :)
     
  19. alex_theman45

    alex_theman45

    Joined:
    Oct 21, 2014
    Posts:
    1
    My Restart Text is not showing, and I don't know why. Can anyone help me?
    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. public int hazardcount;
    9. public float spawnWait;
    10. public float startWait;
    11. public float waveWait;
    12.  
    13.  
    14. public GUIText scoreText;
    15. public GUIText restartText;
    16. public GUIText gameOverText;
    17.  
    18. private bool gameOver;
    19. private bool restart;
    20. private int Score;
    21. void Start ()
    22. {
    23. gameOver = false;
    24. restart = false;
    25. restartText.text = "";
    26. gameOverText.text = "";
    27. Score = 0;
    28. UpdateScore ();
    29. StartCoroutine (SpawnWaves ());
    30. }
    31. void Update ()
    32. {
    33. if (restart)
    34. {
    35. if (Input.GetKeyDown (KeyCode.R))
    36. {
    37. Application.LoadLevel (Application.loadedLevel);
    38. }
    39. }
    40. }
    41. IEnumerator SpawnWaves ()
    42. {
    43. yield return new WaitForSeconds (startWait);
    44. while (!gameOver) {
    45. for (int i = 0; i < hazardcount; i++)
    46. {
    47. Vector3 spawnPosition = new Vector3 (Random.Range (-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
    48. Quaternion spawnRotation = Quaternion.identity;
    49. Instantiate (hazard, spawnPosition, spawnRotation);
    50. yield return new WaitForSeconds (spawnWait);
    51.  
    52. }
    53. yield return new WaitForSeconds (waveWait);
    54.  
    55. if (gameOver = true)
    56. {
    57. restartText.text = "Press R to Restart";
    58. restart = true;
    59. break;
    60. }
    61. }
    62. }
    63.  
    64. public void AddScore (int newScoreValue)
    65. {
    66. Score += newScoreValue;
    67. UpdateScore ();
    68. }
    69. void UpdateScore ()
    70. {
    71. scoreText.text = "Score:" + Score;
    72. }
    73. public void GameOver ()
    74. {
    75. gameOverText.text = "Game Over";
    76. gameOver = true;
    77. }
    78. }
     
  20. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Morning,

    from a quick look, on line 55
    Code (CSharp):
    1. if (gameOver = true)
    you only have one equals sign with is an assignment operator, change this to
    Code (CSharp):
    1.  if (gameOver == true)
    or just simply
    Code (CSharp):
    1. if (gameOver)
    this will make the equality check.
     
  21. Trent57

    Trent57

    Joined:
    Oct 24, 2014
    Posts:
    1
    good afternoon,

    I have a question on the part 6 of the tutorial : "Moving the player"

    In the end of the video, we are adding a part of the code that make the ship tilt to the right or to the left with the speed of the ship along the x axis.

    The function we use for that is Quaternion.Euler(x,y,z).

    We want a rotation around the z axis, so x and y are 0, and the z depend on our speed multiply by a factor that we call tilt.

    But the point that I do not get is that on the documentation, it is write like this :

    As I understand, this not mean Quaternion.Euler(x,y,z), but Quaternion.Euler(z,x,y).

    So this is not the two first term of the input that are equal to zero, but the two last.

    And in the game, obviously, it do not work as in the description, but as in the tutorial.

    So, is the description false ? Or I loose something to understand exactly what it mean ?

    I have not finished this tutorial yet (the part 6 was my last), but it is a great one, and really well made to understand how we use unity, and how to code, in order to make a game.

    Thanks in advance for the answer.

    P.S. : sorry for my bad english, I am not use to write in this langage.
     
    Last edited by a moderator: Oct 30, 2014
  22. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Well, from memory, that description is ambiguous, but not incorrect. It does what is says: z degrees around z axis, x degrees around x axis, y degrees around y axis. I don't know if the order of rotation is in that order or not as it's being translated into the quaternion. Practically, however, you need to follow the signature of the function, which is the order of x, y, z.
     
  23. IanSmellis

    IanSmellis

    Joined:
    Nov 2, 2014
    Posts:
    26
    I cannot seem to get the Enemy Ship and the Player Ship to explode with the explosion animations. When I hit them with a bullet they still die and I get the points, if they hit me with a bullet I just die, and if we collide we both die...All no animations. Just disappearing.

    Any ideas?

    Thanks
    Ian
     
  24. zeropoint101

    zeropoint101

    Joined:
    Mar 2, 2014
    Posts:
    8
    Hi. This is a nice tutorial. Thank you. I found a problem though that caused me a LOT of confusion as a beginner.

    When I started the "Spawning Waves" tutorial, the asteroids in the video would explode when they hit each other. Mine wouldn't. I finally figured out it's because the asteroid was not a trigger collider. In the Creating Hazards video at one point, he says they are not interacting because "they are both trigger colliders", but you can clearly see his trigger checkbox is not checked. I went all through the videos and he never checked his at any point that the student watching the video can see, and never instructed us to do so. Therefore I never did.

    I even noticed in this forum thread that you said it was "optional" for the asteroid to be a trigger collider, but to make the tutorial work properly, it's not optional. This really needs to be corrected, at least with an annotation if nothing else, for people like me who are very detail oriented and trying to follow every step.
     
  25. zeropoint101

    zeropoint101

    Joined:
    Mar 2, 2014
    Posts:
    8
    Ok, I realized I have a question right at this point too. It doesn't matter for the game itself as the script is changed after this point, but I'd still like to understand.

    At the point where you first put in the "for" loop and put the hazardCount at 10, the game starts and creates 10 asteroids at the same time. But why do I end up with anywhere from maybe 12 to 20 explosions?
     
  26. IanSmellis

    IanSmellis

    Joined:
    Nov 2, 2014
    Posts:
    26
    I got it..had to change the explosion prefabs from 0 to 2
     
  27. IanSmellis

    IanSmellis

    Joined:
    Nov 2, 2014
    Posts:
    26
    Now just trying to put it on Android, every time I press on the screen to shoot it sends out a ton at once and keeps shooting until I let go.
     
  28. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    IIRC, you don't need the new keyword for the Vector3.one.

    You should be able to set the value of the new hazard's scale with the value of Vector3.one...
    newHazard.transform.localScale = Vector3.one * scaleValue;

    Or you need to create a new Vector3 object with the value of (1, 1, 1) with:
    new Vector3(1,1,1)

    ... and then set the new hazard's scale with:
    newHazard.transform.localScale = new Vector3(1,1,1) * Vector3.one;
     
  29. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Yup! All of the scripting languages used with Unity are Case sensitivE.

    StArt, Start, start, starT, are all different names!
     
  30. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    If you look in the "Done" folder, you will find enemy ships and firing. You can deconstruct the done scene to see how It was done. There is also a moving starfield example.

    It might be of some value to go to the live training archive in the learn section of the unity site and look for the live session I did on scrolling backgrounds.
     
  31. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    This sounds like you are not checking your time...

    Iirc, the code for instantiating a shot is based on a time variable. If you don't check the time variable, or don't reset the time variable, then you will be able to shoot every frame.
     
    IanSmellis likes this.
  32. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    I will look into this and see what I can find.

    Thanks for the note.
     
  33. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Just a guess... but you seem to have a warning in the console.

    It seems to say "HDR RenderTexture format is not supported on this platform. This camera will render without the HDR buffer.

    Were you experimenting in either player settings or the camera settings?

    Off the top of my head, this doesn't really seem to explain the lack of a skin on your ship... but still... it might be worth checking out the error in the console and trying to find out where it's coming from.

    Now, it's possible to turn your scene gizmos off.

    Here is an image of them at halfway:

    Here is an image of them all the down:


    So, part of your issue could be your gizmos are turned off.

    Now, wireframe mode should look black not blue, like this (and it should *say* wireframe in the left most menu):


    If I select the ship in wireframe mode, I get this:


    ... the mesh is now blue, but I see the collider in green and the scene is still in wireframe mode.

    Can you start this in a new project just to make sure that you have not inadvertently changed some setting that might take us both a long time to find out?

    Then, if it works as expected in a new scene, we can troubleshoot the old one if needs be.
     
  34. BECEJLbE

    BECEJLbE

    Joined:
    Nov 7, 2014
    Posts:
    1
    Hello! I found an error in this tutorial. (Part: MOVING THE PLAYER)

    This code gives the problem:
    Code (CSharp):
    1.  rigidbody.position = new Vector3
    2.         (
    3.             Mathf.Clamp (rigidbody.position.x, boundary.xMin, boundary.xMax),
    4.             0.0f,
    5.             Mathf.Clamp (rigidbody.position.z, boundary.zMin, boundary.zMax)
    6.         );
    The value of "Y" axis is not always equal to 0.
    I think, better to use "rigidbody.position.y".
    Code (CSharp):
    1. rigidbody.position = new Vector3
    2.             (
    3.                 Mathf.Clamp (rigidbody.position.x, vars.Xmin, vars.Xmax),
    4.                 rigidbody.position.y,
    5.                 Mathf.Clamp (rigidbody.position.z, vars.Zmin, vars.Zmax)
    6.                 );
    I changed the variable names, do not pay attention.


    PS: If there were errors in the text, sorry.
    My English is very bad.
     
  35. 0kool

    0kool

    Joined:
    Nov 8, 2014
    Posts:
    1
    Hmmm... I can't see what i'm missing in this ship movement tute. My script Code is identical to the instructors in every way, My inspector is exactly the same as his, my screens are set up precisely the same to the smallest detail, yet he goes into game mode and moves around, i go into game mode and the ship will not move at all. I've seen posts about modifying velocity, I don't have that option...anywhere. the instructor just popped into game mode immediately and started moving, he changed nothing else in the script or the scene. What did I miss and when?

    For clarification i know the tut goes into velocity modifiers in the script because the ship is moving slow, but he can at least make the thing move before the speed part, and i can't.

    UPDATE: fixed it, nevermind lol
     
    Last edited: Nov 8, 2014
  36. IanSmellis

    IanSmellis

    Joined:
    Nov 2, 2014
    Posts:
    26
    Would something like this be suitable?

    Code (CSharp):
    1. if (Input.GetMouseButtonUp(0) && Time.time > nextFire)
    2.         {
    3.             nextFire = Time.time + fireRate;
    4.             Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
    5.             audio.Play();
    6.         }
     
  37. Astaroth

    Astaroth

    Joined:
    Nov 9, 2014
    Posts:
    2
    I have the exact same problem Nephilim_ Shadow has. Everything is done exactly as the tutorial described, but when the tutorial goes into play mode, the ship moves. When I go into play mode, the ship stays still. What is the key or mouse combinations to make it move? Or does something else make it move?
     
  38. Astaroth

    Astaroth

    Joined:
    Nov 9, 2014
    Posts:
    2
    How did you fix it?
     
  39. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    The reason for clamping the y axis to zero, is that you always want you rigidbody.position.y to be 0, but it's possible with physics collisions to get motion on the y axis.

    To eliminate any unwanted movement on the y axis, we set it to 0 at the same time as when we clamp the x & z.

    Another option would be to lock the y axis movement on the rigidbody itself, using the check box, but as we are manipulating the Vector3 already, we might as well do this in code.

    Imagine if we didn't restrict the movement on the y axis: The player ship could begin to drift, and it would quickly drift off the game plane and out of the game area completely.
     
  40. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    I would suggest Input.GetMouseButtonDown(0), rather than Up, so you can hold the button down for auto fire.

    In fact, I'd rather suggest the vide used in the tutorial itself! ( Unless you are trying to change the behaviour of the game...)
     
  41. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    I'll need a little more info to help diagnose the issue. There has to be some discrepancy between the working project and the tutorial, it's just finding it that's going to take a keen eye.

    Can you give us anything to go on? Screenshots? Code?
     
  42. blastedgstar

    blastedgstar

    Joined:
    Nov 11, 2014
    Posts:
    3
    hi guys im a beginner and in ther shooter tutorial moving the player.
    ive copied the c script exact and it wont let me play game to test it it keeps sayin "all compiler errors have to be fixed before you can enter playmode, unityeditor.sceneveiw:showcompilererrornoteification().
    I dont understand can u help this is wat i did
    using UnityEngine;
    using System.Collections;

    public class PlayerControl : MonoBehaviour {
    {
    void FixedUpdate ()
    {
    Float MoveHorizontal = Input.GetAxis ("horizontal")
    float MoveVertical = Input.GetAxis ("vertical");

    Vector3 Movement = New Vector3 (MoveHorizontal,0.0f,MoveVertical);
    }Rigidbody.Velocity = Movement;
     
  43. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Evening,

    Just for a pointer when starting out. try and get used to to error messages and what they are saying, more often that not within the error if you click on it, it will give you a script name and a line number that the error occurs on. when the console states that all compiler errors have to be fixed, it will show you in 'red' in the console window all errors. have a look at the one at the top of the list first, sometimes it may be that one thats throwing all the other errors too.

    from your script that you have copied in, each class and function have curly braces in pairs {} ie, an opening brace and a closing brace for each.

    the end of your code should read;
    Code (CSharp):
    1.  
    2.      Vector3 Movement = new Vector3 (MoveHorizontal,0.0f,MoveVertical);
    3.      rigidbody.velocity = Movement;
    4.   }
    5. }
    if you look at it now you will have an opening and a closing brace for the Class, and inside that an opening and closing brace for the FixedUpdate function.

    have a try and that and see what happens.

    for more info and learning, have a look through some of the live training sessions too, there is a good few hour long sessions there to get a good head start with scripting and unity like 'scripting for beginners' (interesting, theres a good bit in there), they work well in tandem with the tutorial content.
    http://unity3d.com/learn/tutorials/modules/live-training-archive
     
    Last edited: Nov 11, 2014
  44. blastedgstar

    blastedgstar

    Joined:
    Nov 11, 2014
    Posts:
    3
    cud u post exact script for shooter tutorial player movement because it just all vanished and i dont want to get it wrong agen due to my temper
     
  45. blastedgstar

    blastedgstar

    Joined:
    Nov 11, 2014
    Posts:
    3
    still not working got script bk but same message comin up first message line sez { tht icon
    is an unexpected error
     
  46. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    ok, ill do my best to help along until one of the Unity guys gets back to you, you can download and view the complete project, im guessing that you have downloaded it already to use the assets like asteroids, ship graphics etc.. if you look in the 'done' folder there is all the completed scripts for the project.

    sorry for not noticing earlier when i had a quick glance, but there are quite a few errors in that code snipped you posted.
    you have an extra '{' just below public class... at the top of the script.
    you have a capital 'F' in float, where these should be lower case.
    closing braces for FixedUpdate() function should be after you set the rigidbody velocity.
    also missing a closing '}' for class at the end of script.
    also Rigidbody.Velocity should all be in lower case.

    if you dont have the project then I suggest go to asset store and download the project files and have a look in the done folder, should help a great deal :)

    http://unity3d.com/learn/tutorials/projects/space-shooter

    (if you cant get it, PM me your script and ill try and help until the Unity Screencasters get to your assistance)
     
    Last edited: Nov 12, 2014
    IanSmellis likes this.
  47. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
  48. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    When you encounter an error, you can copy and paste the entire error.

    Select the error you want to paste, and then in the lower field in the console, you can copy the entire error and paste it here in the forums.
     
  49. rkmax

    rkmax

    Joined:
    Nov 25, 2014
    Posts:
    2
    I've finished the tutorial, but I built my Android phone HUAWEI G610-U15 runs perfect but in my ME301T tablet (Asus Memo PAD) is not smooth, like jumping frames. including tablet has better hardwarw has a Tecra 3 processor.

    There is some consideration for the application to run properly in both enabled devices?
     
  50. GamerYou

    GamerYou

    Joined:
    Jun 13, 2013
    Posts:
    19
Thread Status:
Not open for further replies.