Search Unity

Space Shooter Tutorial Q&A

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

  1. KAYUMIY

    KAYUMIY

    Joined:
    Nov 12, 2015
    Posts:
    115
    A question comes from PlayerController script.

    Code (CSharp):
    1. [System.Serializable]
    2. public class Boundary
    3.  
    4. {
    5.     public float xMin, xMax, zMin, zMax;
    6. }
    7.  
    8. public class PlayerController : MonoBehaviour {
    9.  
    10.     public float speed;
    11.     public float tilt;
    12.     public Boundary boundary;
    Why do we have to create new class which is Boundary? We can create these fields xMin, xMax, zMin, zMax in the PlayerController script. Why did we create Boundary class and then serialized? Is it for the sake of optimization?
     
  2. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    KAYUMIY,

    It was more for a teaching moment I think. You will use the Boundary class again later on in the "Extending the space shooter" lesson. I don't fully understand the [System.Serializable], but it needs to be there or the program doesn't recognize the Boundary class.

    A general rule of thumb in programming is "if you have to type it more than once, it should go in a method or a class".
     
    KAYUMIY likes this.
  3. nwzebra

    nwzebra

    Joined:
    Dec 4, 2015
    Posts:
    16
    Probably not, although newer versions of the tutorial include a most important PDF file, which talks about the differences needed to run with the current Unity version. Please read. Actually, a better change for this line of code is:
    Code (csharp):
    1.  
    2. SceneManager.LoadScene(SceneManager.GerActiveScene().buildIndex);
    3.  
     
  4. aliant72

    aliant72

    Joined:
    Feb 24, 2017
    Posts:
    2
    Hello everyone, new beginner here.

    I'm having a couple of problems with this tutorial.

    First one:
    About the boundary object that was supposed to destroy the bolts fired from the player.
    I had a strange bug that made the bolt get destroyed at a fixed range from my player.
    I moved the player in the game area but the bolts were not destroyed when leaving the boundary object but at about 8 (unity measure assumed) from the player independently from were the player was in the game area.
    I managed to fix this bug by making the boundary object more "thin" (about 6 or 8 on the y axis)

    Second one:
    When i try to destroy the asteroid with the OnTriggerEnter code in the DestroyByContact script i have the asteroid staying for a couple of seconds in the play area and then getting suddendly destroyed by the Boundary object ( i got this information by putting the Debug command in the DestryByBoundary script) and i don't understand why since the asteroid never leaves the boundary object.

    Any help is much appreciated.


    This link to my project folder in dropbox:
    https://www.dropbox.com/sh/r56kr3663fp83h2/AAA2ijhEKHY0cCvwQOMjG134a?dl=0
     
    Last edited: Feb 25, 2017
  5. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    aliant72,

    You mention making your boundary object thinner. Make sure it is not so thin that as your asteroids rotate they don't accidently hit the boundary edge. Also check your scripting to make sure the asteroids are traveling straight along the Z axis. I had an issue in my script that was constantly adding forces to my asteroid and they would fly in strange directions.

    And make sure gravity is turned off so the asteroids aren't simply falling out of the scene.
     
  6. aliant72

    aliant72

    Joined:
    Feb 24, 2017
    Posts:
    2
    Sorry, i meant "thick"
     
  7. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    Aliant,

    I haven't had time to look at your project yet, were you able to resolve your issues?
     
  8. Urbanwerewolf

    Urbanwerewolf

    Joined:
    Feb 27, 2017
    Posts:
    3
    I just finished the shooting shots video and I don't know how to actually shoot. I don't know how to set Fire1 to an actual key. I'm working in Unity 5.5 and monodevelop. i believe i typed the code exactly but i hit every key and nothing is firing

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

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

    public class PlayerController : MonoBehaviour
    {
    public float speed;
    public float tilt;
    public Boundary boundary;
    private Rigidbody rb;

    public GameObject Shot;
    public Transform ShotSpawn;
    public float fireRate;
    private float nextFire;

    void Start ()
    {
    rb = GetComponent<Rigidbody>();
    }

    void update ()
    {
    if (Input.GetButton("Fire1") && Time.time > nextFire)
    {
    nextFire = Time.time + fireRate;
    Instantiate (Shot, ShotSpawn.position, ShotSpawn.rotation);
    }

    }

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

    Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    rb.velocity = movement*speed;

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

    }
     
  9. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    Urbanwerewolf,

    Change update to Update. Capitalize the 'U'.
     
  10. Breesejo

    Breesejo

    Joined:
    Feb 16, 2017
    Posts:
    1
    Hi,

    I'm having some trouble with building the game with WebGL. I go through the entire process and it hangs on the C+ section. The folder opens, but it's empty. In my console have an error. Any thoughts on what's causing this?

     
  11. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    Breesejo,

    The build has a tendency to stay on the C+ part for a long time, but should still work if you let it process all the way through. If are letting it process all the way and it still isn't working then it is beyond by current knowledge to figure out, just wanted to let you know it is normal to hang there for a long time ( around 5 minutes on my computer).
     
  12. jala528

    jala528

    Joined:
    Feb 28, 2017
    Posts:
    2
    On Unity 5.5 1f1

    My boundary that destroys the bolts is destroying the original prefab. As long as a bolt is on screen I can still shoot but if the last bolt is destroyed I get a "GameObject is destroyed but you are still trying to access it. Here's my code so far. I've tried getting help from the Youtube comments but nothing is working.

    PlayerController

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

    public class PlayerControllerTutorial : MonoBehaviour {

    private Rigidbody rb;
    public float speed;
    public float tilt;
    public Boundary boundary;

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

    private float nextFire;


    private void Start()
    {
    rb = GetComponent<Rigidbody>();
    }

    private 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;
    }
    }

    public void FixedUpdate()
    {
    float moveHorizontal = Input.GetAxis("Horizontal");
    float moveVertical = Input.GetAxis("Vertical");

    Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
    rb.velocity = movement * speed;

    rb.position = new Vector3
    (
    Mathf.Clamp(rb.position.x, boundary.xMin, boundary.xMax),
    0.0f,
    Mathf.Clamp(rb.position.z, boundary.zMin, boundary.zMax)
    );

    rb.rotation = Quaternion.Euler(0.0f, 0.0f, rb.velocity.x * -tilt);
    }
    }

    DestroyByBoundary

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class DestroyByBoundary : MonoBehaviour
    {
    private void OnTriggerExit(Collider other)
    {
    Destroy(other.gameObject.transform.parent.gameObject);
    }
    }
     
  13. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    I think you have a bunch of extra stuff in your Destroy statement.

    Destroy(other.gameObject.transform.parent.gameObject);

    try using

    Destroy(other.gameObject);

    See if that helps.
     
  14. SS_G_SS

    SS_G_SS

    Joined:
    Mar 2, 2017
    Posts:
    2
    When i go to the build settings there isn't a web player choice plz help me
     
  15. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    It is now called WebGL. The option should be there, but you will need to download the module I believe.
     
  16. Simonduck7

    Simonduck7

    Joined:
    Mar 2, 2017
    Posts:
    1
    Hello i am having a problem with the random rotator on the asteroid. I copied the tutorial and the script but for some reason the asteroid stretches and rotates.
    Any help would be appreciated
     
  17. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    Could you post your random rotator script for people here to look at?
     
  18. jala528

    jala528

    Joined:
    Feb 28, 2017
    Posts:
    2
    That doesn't seem to be working either. When using that code the bolts aren't being destroyed but the vfx is, so its just invisible bullets
     
  19. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    jala528,

    If it is no longer destroying the prefab then you have made some progress. You might have something incorrect within your hierarchy. Make sure all the parent child relationships are correct on your prefab.
     
  20. scooterboy

    scooterboy

    Joined:
    Oct 1, 2016
    Posts:
    5
    Issue - playerExplosion VFX isn't getting triggered when Player collides with Asteroid.

    I copied the same code from the tutorial page - https://unity3d.com/learn/tutorials/projects/space-shooter-tutorial/explosions?playlist=17147

    The VFX for the asteroid is working when the shot collides with the asteroid. But when the player collides with the asteroid, then the asteroid just tumbles away and gets destroyed by the boundary.

    Any idea what causes that?

    Version Unity 5.5.0f3
     
  21. scooterboy

    scooterboy

    Joined:
    Oct 1, 2016
    Posts:
    5
    Figured it out. Its because my Player object's mesh collider component's Trigger wasn't switched on. It was a very stupid thing to do.
    The lesson I've learnt is that if you think you're hitting a brick wall, instead of doubting yourself, distract yourself from the problem. You'll get an answer eventually.
     
  22. Urbanwerewolf

    Urbanwerewolf

    Joined:
    Feb 27, 2017
    Posts:
    3
    I need help please! I'm up to explosions and i can shoot and destroy the asteroids but i cannot destroy the player. the colision does occur but i push the asteroid instead of killing the player.

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class DestroyByContact : MonoBehaviour
    {
    public GameObject explosion;
    public GameObject playerExplosion;

    void OnTriggerEnter(Collider other)
    {
    if (other.tag == "Boundary")
    {
    return;
    }
    Instantiate(explosion, transform.position, transform.rotation);
    if (other.tag == "Player")
    {
    Instantiate (playerExplosion, other.transform.position, other.transform.rotation);

    }
    Destroy(other.gameObject);
    Destroy(gameObject);
    }
    }

    please help!
     
  23. Urbanwerewolf

    Urbanwerewolf

    Joined:
    Feb 27, 2017
    Posts:
    3
    thank you very much!!!
     
  24. Halo_Liberation

    Halo_Liberation

    Joined:
    Mar 6, 2017
    Posts:
    26
    hi, i am very very new to the whole C# scripting process and haven't a clue what im doing. this is all so much to take in and im doing my best to keep up and not let the pressure dissuade me. currently i am having issues with the C# PlayerController script for the space shooter tutorial. i have entered it letter for letter even keeping track with the case sensitive but in the end i still only get 2 error codes. this script was apparently wrote back in 2013 and it is now 2017. shouldn't they be updated as the unity engine does? shouldn't the videos also get updated because i think its pretty obvious that people don't hold onto older models of unity and update the minute they can. anyways the codes i get are...

    Assets/scripts/PlayerController.cs(5,14): error CS0101: the namespace `global::' already contains a definition for `Boundary'
    and
    Assets/scripts/PlayerController.cs(10,14): error CS0101: the namespace `global::' already contains a definition for `PlayerController'

    that's using the C# script provided on the unity website. is there anything im doing wrong?
     
  25. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    Urbanwerewolf,

    If your ship is "pushing" the asteroid you most likely have something set incorrectly in your Rigidbody & collider settings. Make sure you have isTrigger set on the appropriate object(s).
     
  26. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    Halo_Liberation,

    Please post your scripts so people can review it. Use code tags if you can to make it easier to read.
     
  27. Halo_Liberation

    Halo_Liberation

    Joined:
    Mar 6, 2017
    Posts:
    26
    oh okay. basically the script i used was the one set for the space shooter tutorial. its the moving the player object tutorial or in a simple way its video 5 for the youtube playlist.. i followed this to the letter and it wouldn't work. so i copied it and pasted it and it gave me the 2 error codes. i tried in a different format to replace all codes using the word "rigidbody" and replaced it with "rb" which still gave me the 2 error codes.

    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;

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

    Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    GetComponent rigidbody = movement * speed;

    rigidbody.position = new Vector3
    (
    Mathf.Clamp (rigidbody.position.x, boundary.xMin, boundary.xMax),
    0.0f,
    Mathf.Clamp (rigidbody.position.z, boundary.zMin, boundary.zMax)
    );

    rigidbody.rotation = Quaternion.Euler (0.0f, 0.0f, rigidbody.velocity.x * -tilt);
    }
    }
     
  28. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    The code you have posted is using scripting from Unity 4.x and it changed in Unity 5.x. You want to get your Rigidbody differently. You will want to make an instance of your Rigidbody in the PlayerController Class, not in the FixedUpdate with the line

    private RigidBody rb;

    and in start put

    rb = GetComponent<Rigidbody>();

    after that whenever you need to reference the Rigidbody ue the rb, for example

    rb.position, or rb.velocity

    Scroll back a little to post #2133 and I put my PlayerController script there. Compare it to yours and see if you can get it going.
     
  29. Halo_Liberation

    Halo_Liberation

    Joined:
    Mar 6, 2017
    Posts:
    26
    okay i will do that. i had read an article that said to replace the term rigidbody with rb after the private rigidbody rb; code but it didn't work. but i will try again. i might have messed it up. also i wanted to thank you for helping. its greatly appreciated
     
  30. Halo_Liberation

    Halo_Liberation

    Joined:
    Mar 6, 2017
    Posts:
    26
    I have attached to this an image of my code. It uses the proper rb script for rigidbody, and im still only getting 2 code issues. Hopefully seeing the image will be a better shot at understanding it then me talking about something i dont know. if anyone can offer advise that would be greatly appreciated. And just for precaution I will write it out exactly how i wrote it. Case sensitive of course... also the post cant have the proper indention so sorry for that. If you are good at scripting then i hope you can understand it even though its not indented like it should be.

    using UnityEngine;
    using SytemCollections;

    [System.Serializable]
    public class Boundary
    {
    public float xMin, xMax, zMin, zMax;
    }
    public class PlayerController : MonoBehaviour
    {
    private Rigidbody rb;

    void start ()
    {
    rb = GetComponent<Rigidbody> ();
    }
    public float speed;
    public float tilt;
    public Boundary boundary;

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

    Vector3 movement = new Vector3 (movementHorizontal, 0.0f, moveVertical);
    rb.Velocity = some Vector3 value;

    rb.position = new Vector3
    (
    Mathf.Clamp (rb.position.x, boundary.xMin, boundary.xMax)
    0.0f
    Mathf.Clamp (rb.position.z, boundary.zMin, boundary.zMax
    );

    rb.rotation = Quaternion.Euler (0.0f, 0.0f, rb.velocity.x * -tilt);
    }
    }




    That is my code typed out for you exactly as it is on my computer. Im getting error codes on lines 5 and 10 for public class boundary and for public class PlayerController : MonoBehaviour

    And im not sure what to do. If you look at the file attached to this post then you should be able to see the error code.
     

    Attached Files:

    Last edited: Mar 8, 2017
  31. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    Halo_Liberation,

    Code looks good, so now lets consider your errors.

    Namespaces are basically a way to prevent, or allow depending on how you look at it, duplicate names for classes and variables etc. Your errors are saying the current namespace already has a Boundary Class and a Player Controller class. The first thing I would check is if you somehow have duplicated your player control script.

    Another thought. The project comes with a completed projects folder, perhaps the script that came with that project somehow got attached to an object.

    So go through your project and make sure you don't have a Boundary class or player class already defined somewhere else.
     
  32. SS_G_SS

    SS_G_SS

    Joined:
    Mar 2, 2017
    Posts:
    2
    Thx
     
  33. Halo_Liberation

    Halo_Liberation

    Joined:
    Mar 6, 2017
    Posts:
    26
    alright, i will do that. i never would have thought of that with all honesty.
    edit: okay i just went through all the files and actually found 3 files that somehow copied themselves. i deleted them all and reentered the code. i was able to play but the ship wont move. i did check and set the speed to 5 for safety and double checked the code to find that i forgot to change the part in the script where it should say

    rb.Velocity = some Vector3 value;

    after making the proper change it now pops an error code saying

    Assets/scripts/PlayerController.cs(28,21): error CS1525: Unexpected symbol `Vector3'
     
    Last edited: Mar 8, 2017
  34. Halo_Liberation

    Halo_Liberation

    Joined:
    Mar 6, 2017
    Posts:
    26
    Okay so far without adding the laser script this is what i have. I dont exactly understand why Vector3 is not wanting to work. Everything should be correct although with unity 5 thats not a solid statement. Any ideas on how to correct it?
     

    Attached Files:

  35. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    Halo_Liberation,

    Looking at the picture, the line rb.velocity = some Vector3 value is not an actual statement. It is just the way the instructor uses to explain how to figure out what you need to use. The "some Vector3 value" needs to be replaced with an actual value, in this case the movement Vector3.


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

    3. Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);

    4. rb.velocity = movement * speed;

    5. rb.position = new Vector3
    6. (
    7. Mathf.Clamp(rb.position.x, boundary.xMin, boundary.xMax),
    8. 0.0f,
    9. Mathf.Clamp(rb.position.z, boundary.zMin, boundary.zMax)
    10. );
    When posting in the future you should get into the habit of using code tags. It's easy and makes the code much easier to read and diagnose. Just copy the code from the editor using CTRL + C, then in your post here in the tool bar at the top, towards the right side is the insert button, select insert code and in the pop up window use CTRL + V to paste.
     
  36. Halo_Liberation

    Halo_Liberation

    Joined:
    Mar 6, 2017
    Posts:
    26
    Okay i will. Im not really a computer guy so this is all new to me. Thank you for the advise also, it will make it much easier to explain.
     
  37. Halo_Liberation

    Halo_Liberation

    Joined:
    Mar 6, 2017
    Posts:
    26
    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.     private Rigidbody rb;
    13.  
    14.     void start ()
    15.     {
    16.         rb = GetComponent<Rigidbody> ();
    17.     }
    18.     public float speed;
    19.     public float tilt;
    20.     public Boundary boundary;
    21.  
    22.     void FixedUpdate ()
    23.     {
    24.         float moveHorizontal = Input.GetAxis ("Horizontal");
    25.         float moveVertical = Input.GetAxis ("Vertical");
    26.  
    27.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    28.         rb.velocity = movement * speed;
    29.  
    30.         rb.position = new Vector3
    31.             (
    32.                 Mathf.Clamp (rb.position.x, boundary.xMin, boundary.xMax),
    33.                 0.0f,
    34.                 Mathf.Clamp (rb.position.z, boundary.zMin, boundary.zMax)
    35.             );
    36.  
    37.         rb.rotation = Quaternion.Euler (0.0f, 0.0f, rb.velocity.x * -tilt);
    38.     }
    39. }
    at "rb.velocity = movement * speed;"
    its giving me an error code saying
    NullReferenceException: Object reference not set to an instance of an object
    PlayerController.FixedUpdate () (at Assets/scripts/PlayerController.cs:28)

    i don't know what is going on anymore... i wish unity would just redo the videos
     
  38. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    Code is looking ok now. This might be an issue with the player object First thing I would do is make sure you have a Rigidbody component attached to your player object, and make sure it is not deactivated.

    What I like to do when I get errors is try testing. In this case I might try to comment out line 28 and see if it now puts the same error at line 30, which would confirm suspicion of the rigidbody being the issue.
     
  39. Halo_Liberation

    Halo_Liberation

    Joined:
    Mar 6, 2017
    Posts:
    26
    Okay, i had to google how to comment a line which i never would have figured out, but i did get the NullReferenceException error but its not specifying line 30. Its going after line 32.

    Mathf.Clamp (rb.position.x, boundary.xMin, boundary.xMax),
     
  40. Halo_Liberation

    Halo_Liberation

    Joined:
    Mar 6, 2017
    Posts:
    26
    hey i found a code that helped my ship move!
    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.     private Rigidbody rb;
    13.  
    14.     void start ()
    15.     {
    16.         rb = GetComponent<Rigidbody> ();
    17.     }
    18.  
    19.     public float speed;
    20.     public float tilt;
    21.     public Boundary boundary;
    22.  
    23.     void FixedUpdate ()
    24.     {
    25.         Rigidbody rb = GetComponent<Rigidbody> ();
    26.  
    27.         float moveHorizontal = Input.GetAxis ("Horizontal");
    28.         float moveVertical = Input.GetAxis ("Vertical");
    29.  
    30.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    31.         rb.velocity = movement * speed;
    32.  
    33.         rb.position = new Vector3
    34.             (
    35.                 Mathf.Clamp (rb.position.x, boundary.xMin, boundary.xMax),
    36.                 0.0f,
    37.                 Mathf.Clamp (rb.position.z, boundary.zMin, boundary.zMax)
    38.             );
    39.  
    40.         rb.rotation = Quaternion.Euler (0.0f, 0.0f, rb.velocity.x * -tilt);
    41.     }
    42. }
    you have been very patent and helpful. thank you. sorry if i was a bit of a nuisance also
     
    Last edited: Mar 10, 2017
  41. CloudFs

    CloudFs

    Joined:
    Jun 19, 2014
    Posts:
    64
    Episode 9 .
    what is AngularVelocity and insideUnitSphere i couldn't understand them using google
    and the documentation on insideUnitSphere didn't help to understand it either

    and how is it that the frame is updating and the asteroid is turning around when the function is written in start and not update ?
    thank you !
     
  42. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    If I understand your second question correctly, basically what is happening is a force is being applied in one direction and drag was turned off. By turning off the drag (setting drag to 0) you will now have perpetual motion, there is nothing to stop the asteroid. That is why the force is not required to be applied every frame.
    However, if you do apply force every frame (I did by mistake) the asteroid will fly off in all sorts of directions because the asteroid is rotating, the direction of force will be different each frame.

    insideUnitSphere just means a point inside of a sphere. Imagine a basketball or soccer ball, and pick a spot anywhere inside of it. That is all it means. Now imagine dead center of the ball is where your x, y and z axis' meet (called origin). Draw a straight line from the origin to the point and that would be your angular velocity, which is basically a force applied at and angle.

    There is a ton of math involved with it that I am totally unqualified to speak of, but hopefully that helps.
     
  43. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    Glad you got your ship moving Halo_liberation. Stick with it, it becomes clearer after while.
     
  44. Halo_Liberation

    Halo_Liberation

    Joined:
    Mar 6, 2017
    Posts:
    26
    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.     public GUIText scoreText;
    14.     private int score;
    15.  
    16.     void Start ()
    17.     {
    18.         score = 0;
    19.         UpdateScore ();
    20.         StartCoroutine (SpawnWaves ());
    21.     }
    22.  
    23.     IEnumerator SpawnWaves ()
    24.     {
    25.         yield return new WaitForSeconds (startWait);
    26.         while (true)
    27.         {
    28.             for (int i = 0; i < hazardCount; i++)
    29.             {
    30.                 Vector3 spawnPosition = new Vector3 (Random.Range (-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
    31.                 Quaternion spawnRotation = Quaternion.identity;
    32.                 Instantiate (hazard, spawnPosition, spawnRotation);
    33.                 yield return new WaitForSeconds (spawnWait);
    34.             }
    35.             yield return new WaitForSeconds (waveWait);
    36.         }
    37.     }
    38.  
    39.     public void AddScore (int newScoreValue)
    40.     {
    41.         score += newScoreValue;
    42.         UpdateScore ();
    43.     }
    44.  
    45.     void UpdateScore ()
    46.     {
    47.         scoreText.text = "Score: " + score;
    48.     }
    49. }
    okay so im on the counting points tutorial. oddly enough i updated the code for the GameController script and now for insert reason here the asteroids don't spawn. my ship is there and the bolts spawn along with the proper sound and background music. where in this code is the source of my problem? i doubled checking it and others said it looked fine. any suggestions
     
  45. crystalwizard321

    crystalwizard321

    Joined:
    Mar 12, 2017
    Posts:
    23
    Right at the beginning of lesson 1, after importint the tutorial package from the asset store, the video says to change the build settings to web player. But on my version of Unity, which is 5.5.2f1 there is no web player option under build settings. There's a webGL, and i suppose it might have been renamed to that, but I'd like to make sure.
     
  46. Knight007au

    Knight007au

    Joined:
    Mar 12, 2017
    Posts:
    1
    Yes the webGL is the new version of export to web.
    You may need to download the module if you need it there will be a button for it once selected.
     
  47. crystalwizard321

    crystalwizard321

    Joined:
    Mar 12, 2017
    Posts:
    23
    next questions

    The tutorial has you change the ratio settings in player settings, and then select Web so that you see the tall thin rectangle in your game window.

    But the new WebGL doesn't have the Web button like it shows on the interface in the tutorial. All it has are 2 buttons - one marked default and one marked minimal. Any idea which one will do what the tutorial is trying to teach?

    Also

    - on the WEbGL options in the build settings there are three check boxs: Development Build, Use Pre-built Engine, and Autoconnect ;profiler. The tutorial says nothing about these. Where can I find what they do?[
     
    Last edited: Mar 12, 2017
  48. bwainscott

    bwainscott

    Joined:
    Feb 18, 2017
    Posts:
    1
    question about BGScroller script: why is GetComponent used to get a reference to the objects transform?

    Compare the usage to the transform being used directly in DestroyByContact and EvasiveManeuver (Evade) without using GetComponent first.

    To experiment, I commented out the GetComponent<Transform>() in BGScroller, changed the "tr." to "transform." whereever it occured, and ran the game. The background worked the same and no errors were displayed.

    Did I miss some important guidelines for the transform component?
     
  49. crystalwizard321

    crystalwizard321

    Joined:
    Mar 12, 2017
    Posts:
    23
    So many things in this tutorial no longer work in Unity 5. i can't set my game view to be a long thin rectangle in player settings for export to the web. I can't set any ratios for any of the platforms, infact, other tan windows/linux because the only platform that now has a ratio setting is windows/linux. I can't drag the numbers back and forth in the transform settings in the game view like he does in the tutorial I can enter numbers but i can't just drag my mouse to get the numbers to change. There is a ton of errata in the update notes on other things that have changed.

    It's incredibly frustrating to try to learn this basic stuff when using a tutorial that no longer works the way the application does.

    Are there any basic tutorials for unity 5?
     
  50. crystalwizard321

    crystalwizard321

    Joined:
    Mar 12, 2017
    Posts:
    23
    The errata guide for Unity 5 states that there are no known issues for lesson 7 Shooting shots. There's an issue.

    the code for Input.GetButton shows a short function using time.time. In order to find that code, which is no longer the Input.GetButton code in the scripting refrence, you have to search google for time.time. If you go to Input.GetButton in the Unity scripting API refrence either with monodevelop or just a google search, you get a much longer function useing time.deltatime.