Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

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
    I am learning Converting Part in Space Shooter project. When I was creating Image in Hierarchy, there was not Touch Input Module attached to EventSystem. So I added myself. However, after I wrote SimpleTouchPad script, player did not move anymore. When touch my iPad in TouchZone , it showed position of touch because of Debug.Log(direction). However, played was not moving. In addition, no any bug or mistake in my code.
     
  2. Aenigmaticus

    Aenigmaticus

    Joined:
    Apr 7, 2016
    Posts:
    54
    @squall-lionheart - What is the intended behaviour with your MoveToPlayer script?
     
  3. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    The touch input module has now been incorporated into the standalone input module. It should be renamed simply input module.
     
    KAYUMIY likes this.
  4. KAYUMIY

    KAYUMIY

    Joined:
    Nov 12, 2015
    Posts:
    115
    Do I have to add something? Player was not moving in sprite of the fact that Touch Input Module attached or not.

    Untitled.jpg
     
  5. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Have you double checked all your steps? If you've followed every step in the tutorial accurately, it should just work. Try deploying it to the device to rule out any editor issue. I've tested the completed app on my iPad and it worked as expected.

    If you're still having trouble after double checking, can you please post as many details of your problem as possible?

    We need enough information to be able to know what your issue is, exactly, to be able to solve it.

    Please write a complete and accurate description of your problem and include any relevant supporting material, such as screen captures and code snippets.

    Please display any images in-line so we can see them easily and post any code snippets using code tags. (How to use code tags: http://forum.unity3d.com/threads/using-code-tags-properly.143875/)
     
    KAYUMIY likes this.
  6. Aenigmaticus

    Aenigmaticus

    Joined:
    Apr 7, 2016
    Posts:
    54
    @squall-lionheart - So I have resolved the issues related to my custom background scroller speed adjustments, and I have incorporated the wave hazard speed incrementation logic. I just need to know if you still need the assistance? If so, I will post all the steps needed to replicate the results.
     
  7. DakotaRSmith

    DakotaRSmith

    Joined:
    May 6, 2016
    Posts:
    1

    Funny, mine was marked convex, still had the error in NullReference error in the compiler. un marked Convex, remarked it, saved and then it worked.

    Strange.
     
  8. Shags

    Shags

    Joined:
    Apr 28, 2016
    Posts:
    24
    Hi Adam,
    I am having trouble running my build. It builds successfully but I can't get it to run on my ipad. I have paid for my apple membership, and have registered it as a testing device but still I can not get it to run. I would appreciate any help you can give me.
     
  9. GodzWrath

    GodzWrath

    Joined:
    Apr 27, 2016
    Posts:
    10
    Does anyone have any ideas on how to create a difficulty setting? I have been trying to do this in one scene (settings/mainmenu) but haven't been able to get a variable to transfer over. The real issue is having a variable that is defined in one script and then called in another, which I thought I knew, but must not.
     
  10. jusw85

    jusw85

    Joined:
    Apr 21, 2016
    Posts:
    21
  11. greatness

    greatness

    Joined:
    Feb 20, 2016
    Posts:
    199
    I can't seem to build the game. First of all, I can't save the scene as anything. I just select the folder Builds, and it builds the game. But when I click on the html folder, it just opens Visual Studio and shows some random stuff. This opening of Visual Studio happened before when I clicked the blue book near components. What is going on? Is it just me or Unity?
     
  12. P_R_O

    P_R_O

    Joined:
    May 10, 2016
    Posts:
    2
    Why my Bolt(Clone) is always dropping it's Y axis after it was shoot? It made my Bolt can only travel through a short distance and it was destroyed.
     
  13. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Morning,

    Check in your bolt prefab that ' use gravity' is not selected, (you will find this in the Rigidbody component in the inspector, its a tickbox) as this will cause your bolt to drop in Y axis when fired, and out of boundary.
     
    Last edited: May 10, 2016
  14. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Afternoon,
    Lets start with the saving of a scene.
    Can you save your scene within Unity, does your project save ok?
    Have you restarted unity?

    What platform are you building for, sounds like web, WebGL?
    As far as im aware building for WebGL does not give you the option to save as a specific filename, it automatically saves it as index.html in your build folder.
    http://docs.unity3d.com/Manual/webgl-building.html

    Is it running the game after build thats causing problems, just wondering as you say you cant build, but then you say you can?

    what operating system are you running? im just wondering as you say that the project, and reference document shortcuts in inspector open up visual studio. Can you check what your default internet browser is within your OS, as it may be Visual Studios internal browser.

    Worth a look.
     
  15. shazzer9

    shazzer9

    Joined:
    May 11, 2016
    Posts:
    1
    Hey, any tips on creating a Highscore display when the game ends and saving it so that when i restart the game the Highscore remains there until it is beaten by a new Highscore??
     
  16. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    There is a live training session that covers Data Persistence, might be a bit code heavy when starting out.. but worth a watch.
    http://unity3d.com/learn/tutorials/...ersistence-data-saving-loading?playlist=17117

    Maybe look at the playerprefs to begin with.
    http://docs.unity3d.com/ScriptReference/PlayerPrefs.html
     
    shazzer9 likes this.
  17. KAYUMIY

    KAYUMIY

    Joined:
    Nov 12, 2015
    Posts:
    115
    Hello Adam Buckner
    Can I ask question related to Survival Shooter project.
    I send a question on that forum, yet, I have not got answer yet.
     
  18. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
  19. greatness

    greatness

    Joined:
    Feb 20, 2016
    Posts:
    199
    How do you insert the mobile artwork to the game? I already downloaded the artwork but how do you insert it into an asset that I can use in my unity project.
     
  20. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Should be able to just drag and drop your art asset into the project window within the editor depending on what it is.

    Have a little look at the 2D Intro, the folder view is briefly covered there (ive marked the time)
     
  21. greatness

    greatness

    Joined:
    Feb 20, 2016
    Posts:
    199
    What is Quaternion.FromToRotation. I didn't get the whole concept on that calibrating that accelrometer.
     
  22. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836

    When using a tablet/phone or any device that uses the accellerometer, if you hold it at any angle other than straight facing up, it has to record how you are holding the device, and what orientation it is starting on.

    So this is stored as a baseline, then when you tilt the device, it records the current accellerometer position and offsets that against the position it started from (the reference accellerometer reading) so you get a nice smooth movement based on the rotation of your device when the game started.
     
  23. ladyonthemoon

    ladyonthemoon

    Joined:
    Jun 29, 2015
    Posts:
    236
    Hi,

    I'm doing this tutorial; so far, so good. Using the Space Shooter upgrade guide was a great help and, I managed applying some things I had learnt before in scripting and found out solutions by myself! (Very proud here. :D)

    There is a tiny little problem though: when both the ship and an asteroïd bump into each other and explode we can hear only the sound of the asteroîd exploding. I have added the player exploding sound to the "explosion_player" VFX prefab as instructed in the video.

    Ahem, after listening more carefully, it appears that the sound we can hear is a combination of both explosions sounds. My bad; sorry. ;)
     
    Last edited: May 18, 2016
  24. ladyonthemoon

    ladyonthemoon

    Joined:
    Jun 29, 2015
    Posts:
    236
    Is this... spam?
     
  25. OneProGoober

    OneProGoober

    Joined:
    May 11, 2016
    Posts:
    50
    Mathf.clamp is not working correctly for me for my specific implementation!
    BUT IT WORKS FINE IF I USE THE COPY OF THE SCRIPT THEY PROVIDED (after a few small edits).
    Here is the code that I wrote:

    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>().velocity = movement*speed;

    float positionX = GetComponent<Rigidbody>().position.x;
    float positionZ = GetComponent<Rigidbody>().position.y;

    GetComponent<Rigidbody>().position =
    new Vector3(Mathf.Clamp(positionX, boundary.xMin, boundary.xMax),
    0.0f,
    Mathf.Clamp(positionZ, boundary.zMin, boundary.zMax));

    GetComponent<Rigidbody>().rotation =
    Quaternion.Euler(0.0f, 0.0f, GetComponent<Rigidbody>().velocity.x* -tilt);
    }
    }

    Here is the code they provided (after editing to fix the obsolete getcomponent):

    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>().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);
    }
    }


    =======

    My x coordinates will update, but the z will not. I can't move my ship up and down in the game at all (well I can technically move it up and down .2 units (which of course has to do with the speed set to 10 and the fact that we only update one frame on FixedUpdate (which happens every .02 seconds.))) I just want to figure out the actual reason behind it - I don't care too much for the actual solution since I can make it work if I use their implementation.
     
  26. ladyonthemoon

    ladyonthemoon

    Joined:
    Jun 29, 2015
    Posts:
    236
    What is your "specific implementation"?
     
  27. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Morning,

    One thing I noticed that when you are getting the position of the Rigidbody, you are setting your PositionX variable to the 'y' position of the Rigidbody, which will never change as the game is running on the X / Z plane and the Y is zero.

    Code (CSharp):
    1. float positionZ = GetComponent<Rigidbody>().position.y;
    if you change this to
    Code (CSharp):
    1. float positionZ = GetComponent<Rigidbody>().position.z;
    see how that goes.


    Just for future reference, if you dont mind, when posting code if you can use code tags please, as it makes it soo much easier to read in the post ;)

    http://forum.unity3d.com/threads/using-code-tags-properly.143875/
     
  28. ladyonthemoon

    ladyonthemoon

    Joined:
    Jun 29, 2015
    Posts:
    236
    I've almost finished the tutorial; I'm at the stage where we set up the game so that is ends. The upgrade guide says that there is no known issue at that stage but I've got one (and a half one):

    1) In the script added to the Game Controller, we use several times "gameOver", as boolean variable and as a function. The parser refuse to compile the script because "The type `GameControllerScript' already contains a definition for `gameOver'". Modifying the function name from:

    Code (CSharp):
    1. public void gameOver()
    2.     {
    3.         gameOverText.text = "Game Over!";
    4.         gameOver = true;
    5.     }
    to:
    Code (CSharp):
    1. public void gameIsOver()
    2.     {
    3.         gameOverText.text = "Game Over!";
    4.         gameOver = true;
    5.     }
    (and updating the DestroyByContact script) fixes the problem.
    2) The Game Controller script works perfectly but Unity sends me warnings regarding Application.LoadLevel, saying:
    and
    The documentation also says that they are obsolete (http://docs.unity3d.com/ScriptReference/Application.LoadLevel.html and http://docs.unity3d.com/ScriptReference/Application-loadedLevel.html), but, as I said, the script works perfectly. So...

    The scripts:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class GameControllerScript : 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.     public GUIText scoreText;
    13.     public GUIText restartText;
    14.     public GUIText gameOverText;
    15.  
    16.     private bool restart;
    17.     private bool gameOver;
    18.     private int score;
    19.  
    20.     void Start ()
    21.     {
    22.         gameOver = false;
    23.         restart = false;
    24.         restartText.text = "";
    25.         gameOverText.text = "";
    26.         score = 0;
    27.         UpdateScore ();
    28.         StartCoroutine (SpawnWaves ());
    29.     }
    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.  
    42.     IEnumerator SpawnWaves ()
    43.     {
    44.         yield return new WaitForSeconds (startWait);
    45.         while (true)
    46.         {
    47.             for (int i = 0; i < hazardCount; i++)
    48.             {
    49.                 Vector3 spawnPosition = new Vector3
    50.                     (
    51.                         Random.Range (-spawnValues.x, spawnValues.x),
    52.                         spawnValues.y,
    53.                         spawnValues.z
    54.                     );
    55.                 Quaternion spawnRotation = Quaternion.identity;
    56.  
    57.                 Instantiate (hazard, spawnPosition, spawnRotation);
    58.                 yield return new WaitForSeconds (spawnWait);
    59.  
    60.             }
    61.             yield return new WaitForSeconds (waveWait);
    62.  
    63.             if (gameOver)
    64.             {
    65.                 restartText.text = "Press 'R' for Restart";
    66.                 restart = true;
    67.                 break;
    68.             }
    69.         }
    70.     }
    71.  
    72.     public void AddScore (int newScoreValue)
    73.     {
    74.         score += newScoreValue;
    75.         UpdateScore ();
    76.     }
    77.  
    78.     void UpdateScore ()
    79.     {
    80.         scoreText.text = "Score: " + score;
    81.     }
    82.  
    83.     public void gameIsOver()
    84.     {
    85.         gameOverText.text = "Game Over!";
    86.         gameOver = true;
    87.     }
    88. }

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class DestroyByContactScript : MonoBehaviour
    5. {
    6.     public GameObject explosion;
    7.     public GameObject playerExplosion;
    8.     public int scoreValue;
    9.  
    10.     private GameControllerScript gameControllerScript;
    11.  
    12.     void Start ()
    13.     {
    14.         GameObject gameControlerObject = GameObject.FindWithTag ("GameController");
    15.  
    16.         if (gameControlerObject != null)
    17.             gameControllerScript = gameControlerObject.GetComponent<GameControllerScript>();
    18.  
    19.         if (gameControlerObject == null)
    20.             Debug.Log ("Cannot find the 'Game Controller' Script");
    21.     }
    22.  
    23.     void OnTriggerEnter(Collider other)
    24.     {
    25.         if (other.tag == "Boundary")
    26.         {
    27.             return;
    28.         }
    29.             Instantiate (explosion, transform.position, transform.rotation);
    30.             gameControllerScript.AddScore (scoreValue);
    31.  
    32.         if (other.tag == "Player")
    33.         {
    34.             Instantiate (playerExplosion, other.transform.position, other.transform.rotation);
    35.             gameControllerScript.gameIsOver ();
    36.         }
    37.             Destroy (other.gameObject);
    38.             Destroy (gameObject);
    39.  
    40.     }
    41. }

    I hope this will be useful. :)
     
    Last edited: May 19, 2016
  29. OneProGoober

    OneProGoober

    Joined:
    May 11, 2016
    Posts:
    50
    Wow I can't believe I missed this. Turns out I shouldn't do anything when I'm tired :S
     
  30. Araxus

    Araxus

    Joined:
    May 20, 2016
    Posts:
    2
    Hi all, not sure if this has been answered at all yet (there is a lot of pages on this thread now) but I have been extending the Space Shooter game and have had no issues till I created the EvasiveManeuver script. the error I am currently getting is:

    "NullReferenceException: Object reference not set to an instance of an object EvasiveManeuver.FixedUpdate () (at Assets/Scripts/Evasivemaneuver.cs:40"

    after clicking on this error I am pointed to the script line:

    float newManeuver = Mathf.MoveTowards (rb.velocity.x, targetManeuver, Time.deltatime * smoothing);

    despite looking over the video and the sample code on the page below the video my code is identical to supplied, yet it does not appear to work, I have watched over the same section of video to see if I had missed anything and either my brain is skipping over something continually or there is something else causing the issue.
     
  31. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836

    Afternoon,

    from the error you are getting, it sounds like the Rigidbody reference variable 'rb' is trying to be used but it has not been assigned a value. so the error is a NullReference where something has been declared, not assigned anything (null) and is trying to be used.

    Couple of things to check.
    Have you declared the Rigidbody variable at the top of the script?
    Code (CSharp):
    1. private Rigidbody rb;
    your Start Method, does this have a capital S? as if its lower case it wont get called, or generate any errors.
    Code (CSharp):
    1.     void Start ()
    2.     {
    are you getting the Rigidbody and assigning it to rb within the Start method?
    Code (CSharp):
    1. rb = GetComponent<Rigidbody>();
    see if its any of those areas that are causing the Gremlins.
     
    Last edited: May 20, 2016
  32. seroj007

    seroj007

    Joined:
    May 21, 2016
    Posts:
    7
    Hi
    I been stuck for two days on Space Shooter.
    It just doesn't load Player Ship in the scene. its in mesh form, it doesn't accept physics colliders.
    I have tried most unity versions and all the same.
     
  33. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Is it the Player Game Object video your working through?
    just to confirm, is it the 'vehicle_playerShip' in the root of the Models folder (blue cube type icon) that you are dragging to the scene heirarchy?
     
  34. seroj007

    seroj007

    Joined:
    May 21, 2016
    Posts:
    7
    I am dragging the Vehicle_playerShip as explained in the video. The icon is the ship itself, but ended up something else in me scene. . the ship doesn't move in its complete shape but as a mesh and does not accept any colliders. been following the tutorial step by step over 7 times, still the same.
     
  35. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Have you got a screenshot at all please, to show what you have in the scene, just to try and get an idea on what your seeing.
     
  36. seroj007

    seroj007

    Joined:
    May 21, 2016
    Posts:
    7
    screenShot attached. I have simply been dragging and dropping the actual ship in screen but never shown there.
    Thanks
     

    Attached Files:

  37. seroj007

    seroj007

    Joined:
    May 21, 2016
    Posts:
    7
    Hi again
    After over two days of struggle I noticed I had deselected everything in Layers dropdown menu and selected nothing. cant remember how I have done that but seems to be the problem. Many Thanks for your concern.
    Seroj
     
  38. Jovy83

    Jovy83

    Joined:
    Feb 28, 2015
    Posts:
    15
    I got a few questions regarding the "Extending Space Shooter with Enemies, Hazards, BG scorlling, etc" video.

    How did you know that the screen size is 12 and 40 at 1:30:56 of the video? How did you figure out the size?

    Also for the scrolling background, why did we initially position the duplicate background at the bottom of the original background? We needed to scroll it down for the game, so why not initially position it at the top? What is the difference?

    Also why did we need to set a boundary for the enemy ship on the Z axis? I mean I understand we need the boundary for the X axis so that it doesn't go offscreen on left/right. We don't need to bound the enemy on the Z because once it exceeds the bottom of the screen, its path is over and gets destroyed by our bounding box right?

    Thanks
     
  39. Nemneb

    Nemneb

    Joined:
    May 23, 2016
    Posts:
    1
    Hey guys, I have been going through Unity tutorials, but when I got to the part that I'm supposed to make the player object move, My guy didn't seem to respond to any of my inputs. I looked at the upgrade to 5.0 guide, & I looked at the done script & scene, to see if I have messed anything up their. I looked at my roll a ball project to try & replicate the movement rules. I have found a couple of posts with the same problem, & tried diagnosing this bug accordingly, but still didn't work. I double checked & triple checked capitalization, & spelling. Looked in the InputManager, & everything looked fine. I have also tried a few improvised snippets of code, but still haven't worked.

    Any help is greatly appreciated, & thanks for taking the time to read my post.

    Edit:
    I guess that I didn't quite understand that the console won't worn you when the 'FixedUpdate' or 'Start' isn't properly capitalized. If you have a similar problem, make sure to capitalize properly. Thanks Adam for expanding on another persons problem & reasoning why it might not have worked, now I figured out my code & my guy works phenomenally!
     
    Last edited: May 24, 2016
  40. Araxus

    Araxus

    Joined:
    May 20, 2016
    Posts:
    2
    Hi OboShape, it turned out it was a code ordering error, I reordered the code so that rb = GetComponent<Rigidbody>(); was at the top of the void Start stack and its working fine now, simple things causing the greatest issue.

    Thank you again!
     
  41. seroj007

    seroj007

    Joined:
    May 21, 2016
    Posts:
    7
    Hi guys
    I am in my 5th video of the spaceShooter and everything seems to be good but when I click run I can see the tail of space shooter firing but don't know how to move around. I have click all the buttons but no movement.
    here is my code.
    Many Thanks

    using UnityEngine;
    using System.Collections;

    public class PlayerController : MonoBehaviour {
    private Rigidbody rb;

    public float speed;

    void FixedUpdate ()
    {

    rb = GetComponent < Rigidbody>();
    float moveHorizontal = Input.GetAxis("Horizontal");
    float moveVertical = Input.GetAxis("Vertical");
    Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
    rb.velocity = movement * speed;
    }
    }
     
  42. seroj007

    seroj007

    Joined:
    May 21, 2016
    Posts:
    7
    also I have this yellow warning


    Warning CS0618 'Application.loadedLevel' is obsolete: 'Use SceneManager to determine what scenes have been loaded' Space Shooter.CSharp C:\Users\seroj007\Desktop\Space Shooter\Assets\Done\Done_Scripts\Done_GameController.cs 38 ActiveSeverity Code Description Project File Line Suppression State
     
  43. seroj007

    seroj007

    Joined:
    May 21, 2016
    Posts:
    7
    Thanks to all
    I deselected Kinematic and it works now.
     
  44. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Good that you got the player moving, the warnings you are getting for the Application.LoadLevel, have a look at a previous post about replacing with the SceneManager see if that helps you out.

    http://forum.unity3d.com/threads/space-shooter-tutorial-q-a.313899/page-26#post-2475431
     
  45. dyprogrammer

    dyprogrammer

    Joined:
    May 25, 2016
    Posts:
    1
    Hi, I'm trying to make a modification on this first background scroll script:


    public float scrollSpeed;
    public float tileSizeZ;

    private Vector3 startPosition;

    void Start ()
    {
    startPosition = transform.position;
    }

    void Update ()
    {
    float newPosition = Mathf.Repeat (Time.time * scrollSpeed, tileSizeZ);
    transform.position = startPosition + Vector3.forward * newPosition;
    }
    }

    I'm trying to make it so you scroll two full "tile lengths" then repeat starting from the second tile, rather than the beginning. Essentially this would make it possible for me to start 'launching' from a space station/planet/etc then be able to continually scroll through space afterwards. I can't quite figure this out, can anyone help me out?
     
  46. JMazzer

    JMazzer

    Joined:
    Apr 24, 2016
    Posts:
    1
    Finished the Space Shooter tutorial & the Extended session - everything is working except I'm getting the Game Over! text on the Enemy Ship getting destroyed as well as the player... what did I do?
     
  47. skrap1r0n

    skrap1r0n

    Joined:
    May 31, 2016
    Posts:
    3
    These are great tutorials. I've made it through the roll a ball tutorial and I am now on the space shooter one, and I have run into a snag, that I just cannot noodle out with the RandomRotator Script for the asteroid. I've searched quite a few threads and haven't found it yet, so I am hoping someone can throw me a bone.

    First thing, I am using Unity 5.3.5f1 64bit, and I am on Chapter 2, section 2 "Creating Hazards". Thankfully Unity 5 has been updating the code as I follow along, so I am aware of some of the differences with regard to the need to use

    Code (CSharp):
    1. GetComponent<Rigidbody>().angularVelocity
    instead of
    Code (CSharp):
    1. rigidbody.angularVelocity
    as mentioned in the video.

    The problem I am having is that the asteroid won't tumble. it seemed like maybe the script wasn't attached to the game object, I have verified that it is attached to the Asteroid game object and not the child object, prop_asteroid_01. I have verified that the Game object has a Rigidbody attached, and that there are no constraints on it. I have also verified that the tumble variable is filled in with a number that is not zero.Another odd thing that makes me believe there is a disconnect between the script and the object is that the Rotation fields in my transform inspector are all 0's, whereas in the video, I can see there are changing values in those fields.

    I have deleted this script and removed the script component from the game object 3 times and redid it, thinking I might have missed something, but for the life of me, I cannot figure this out.

    Here is the script in question. any help would be greatly appreciated.
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class RandomRotator : MonoBehaviour
    5. {
    6.     public float tumble;
    7.  
    8.     void Start()
    9.     {
    10.         GetComponent<Rigidbody>().angularVelocity = Random.insideUnitSphere * tumble;
    11.     }
    12.  
    13. }
     
  48. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Just as a thought, you could also just create another single starting Tile for your starting station, and have it positioned slightly above the scrolling background moving at the same speed.
    then you could have it move when the game starts and remove it when it leaves the game area.
     
  49. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Hi,

    In your destroy by contact script, are you checking for the Player tag?
    Code (CSharp):
    1.         if (other.tag == "Player")
    2.         {
    3.             Instantiate(playerExplosion, other.transform.position, other.transform.rotation);
    4.             gameController.GameOver();
    5.         }
    or possibly you have have assigned the Player tag instead of Enemy tag to your enemies prefab by accident?
     
  50. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836

    Does the asteroid move down the play area? or is it purely that it wont rotate, and there is a tumble value in the Prefab?
    if its not moving, is the 'is kinematic' ticked as this would stop phyisics interaction?