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

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

  1. NonthinkingMass

    NonthinkingMass

    Joined:
    Jun 6, 2014
    Posts:
    2
    Hi there!

    I encountered a strange thing - while using the RandomRotator script, I did not get the expected results - the asteroid does not rotate. Here is my code:


    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class RandomRotator : MonoBehaviour
    6. {
    7.  
    8.     public float tumble;
    9.     private Rigidbody rb;
    10.  
    11.     void start()
    12.     {
    13.         Rigidbody rb = GetComponent<Rigidbody>();
    14.         rb.angularVelocity = Random.insideUnitSphere * tumble;
    15.     }
    16. }
    Also, I have the script set to Asteroid parent object, the Kinematics is unchecked (somebody had this problem when I searched it).

    Can anybody check the code for any "imperfections"?
     
    ddyson1 likes this.
  2. NonthinkingMass

    NonthinkingMass

    Joined:
    Jun 6, 2014
    Posts:
    2

    I think this happened to me when I had a Rigidbody component on the prop_asteroid asset, as well as on the parent Asteroid object. But not entirely sure.
     
  3. HernestoMV

    HernestoMV

    Joined:
    Oct 19, 2013
    Posts:
    2
    I got a similar problem, Then I just created anyway and realized that you cant't name the game, it is automatically named Index.
     
  4. HernestoMV

    HernestoMV

    Joined:
    Oct 19, 2013
    Posts:
    2
    I had some problems with how the game opens. In first place, I tested on Chrome and Firefox and it only opened on Firefox. Also It doesn't seem to show the entire screen, it cuts a little bit from the top, unless I get on fullscreen mode. I noticed that because the score and restart texts got cut, I changed the offset on both to -50 and it showed as it should, but that's just a not ideal workaround. Then I made a new build, this time I changed the default screen height from 900 to 850, and the game didn't cut anything. I supose there is a way to build the game with size options to correct that problem, but I'm a rookie at this and haven't got to that point yet.

    Lastly, the text appears on different places on default and fulllscreen. The transform position is a percentage on the screen position, so depending on the screen size it changes places (0 is 0% and 1 is 100%). It does't get in the way, just saying this because as I made the game I put the texts inside the game area and then on the build it moved a bit towards the center, then I made another build with the texts on the black part of the screen.
     
  5. Purgatus

    Purgatus

    Joined:
    Jan 24, 2013
    Posts:
    5
    This is such a great learning tool for Unity. Thanks for creating it!.

    I am having an issue on 03. Explosions.

    at the end of the lesson, we add the Mover script to they asteroid and give it a negative value. When I do this, the asteroid spins off in a random direction at game start and not down towards the bottom of my screen. It looks like the mover script is the same:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Mover : MonoBehaviour {
    5.  
    6.     public Rigidbody rb;
    7.     public float Speed;
    8.  
    9.     void Start()
    10.     {
    11.         rb = GetComponent<Rigidbody>();
    12.     }
    13.    
    14.    void FixedUpdate ()
    15.     {
    16.         rb.velocity = transform.forward * Speed;
    17.     }
    18. }
    19.  
    Did I enter something in wrong?

    EDIT: Ok I found my mistake by comparing the done_mover script to my own.

    I thought, as this was physics movement, that it would be in FixedUpdate when it should have been in Start.
     
    Last edited: Sep 13, 2016
  6. Disane

    Disane

    Joined:
    Sep 6, 2016
    Posts:
    2
    I don't know if this has been mentioned here. I tried to search but just something I noticed missing from the unity 5.0 correction. Application.LoadSecene() has been depracated and now instead of using:


    Code (CSharp):
    1.   void Update ()
    2.     {
    3.         if (restart)
    4.         {
    5.             if (Input.GetKeyDown (KeyCode.R))
    6.             {
    7.                 Application.LoadLevel (Application.loadedLevel);
    8.             }
    9.         }
    10.     }
    You need to use the SceneManager:

    Code (CSharp):
    1.  
    2. // Update is called once per frame
    3.     void Update ()
    4.     {
    5.         if (restart)
    6.         {
    7.             if (Input.GetKeyDown (KeyCode.R))
    8.             {
    9.                 SceneManager.LoadScene(SceneManager.GetActiveScene().name);
    10.             }
    11.         }
    12.     }
    13.  
    14.  
    There must be a way to get the current Scene name/index and load that instead of refering to the Scene by it's name ('Main').
    Please update your 5.0 guide!
     
    TaylorFlorian likes this.
  7. bart87

    bart87

    Joined:
    Sep 10, 2016
    Posts:
    12
    Hi

    I started this tutorial one day ago. I created my own 3d models etc. I created also 2d explosion sequence (43 images, first and last are blank)

    everything is fine till I want to add my explosion.
    I have no idea how to add my sequence of 43 images to be animated. also do I should put that on plane as GameObject?

    how I would like to do that:
    1. I would like to create a GameObject and under that create a plane.
    2. Put the script on a plane which create animation from my sequence - one time play
    3. When the asteroids is colide with laser than explosion appear (the plane with animation)
    4. My asteroid is rotated so my 2d plane is rotated as well. How to change the code to be origin like 0 for all rotation axies?

    I done 1 and 2 (no animation)
     
  8. bart87

    bart87

    Joined:
    Sep 10, 2016
    Posts:
    12
    I put all explosion steps into one image, than I created a sprite. The animation is working fine
    but when I shot into asteroid, there is nothing, just asteroid disapear

    anyone know whats wrong ?

    This is the code:


    using UnityEngine;
    using System.Collections;

    public class DestroyByContact : MonoBehaviour
    {
    public Sprite explosion;

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

    I changed line 'public GameObjectexplosion;' into 'public Sprite explosion;'
    to be able to put my sprite animation.

    When was GameObject I put square, so when I shoted the square appears.
    When I changed to sprite, and put my sprite animation. When I shot there is nothing how I said on top of this post.
    Please let me know what I should to change or what improve. THank you
     
    Last edited: Sep 15, 2016
  9. bart87

    bart87

    Joined:
    Sep 10, 2016
    Posts:
    12
    I ve done again so I created proper sprite after move to prefabs its create an GameObject. so I changed my script to GameObject from Sprite. Now when I shot to asteroid the explosion appear but now I need to change an angle of an explosion. because its not on front to the camera because the asteroids is rotating. Any idea? or I will fix it alone again? :D
     
  10. bart87

    bart87

    Joined:
    Sep 10, 2016
    Posts:
    12
    Ok, I have still one small issue

    my asteroid rotate so my explosion which is 2D as well.
    if I am right I need to make fixed rotation for the exposion.

    Instantiate(explosion, transform.position, transform.rotation);
    How to change 'transform.rotation' in this line to put specific number or origin values for
     
  11. Loim

    Loim

    Joined:
    Sep 15, 2016
    Posts:
    2
    The "s" in "start" should be capitalized. I literally had this same problem. If that doesn't fix it, the second "Rigidbody" before the second "rb" seems redundant.
     
  12. EcComicFan

    EcComicFan

    Joined:
    Sep 11, 2016
    Posts:
    7
    Hello there! Just started the Space Shooter tutorial, but I am using Unity 5.4 and there seem to be a lot of differences. There was no game type recommend as to whether or not to create a 3D or 2D game, so I went with 3D. Then there was the issue that Disane alluded to, and now it's not showing an option for Web Player in the build setting.

    I decided to go with WebGL as it seems to be what most people advise and changed the resolution to 600 x 900, but now I can't change my game view resolution to match as there is no WebGL option under the resolution drop down (in the video there was a "Web" option). I used the add button in the drop down and created a new fixed resolution view of 600 x 900. Was this the right way to go? Also, I noticed that the game view in the tutorial is a solid view, whereas min is the standard sort of horizon view. What changes do I need to make to achieve this?

    Finally, is there a detailed resource anywhere that lists the differences for this tutorial with Unity 5.4? Even if it is in text form, it would be nice to know what to look out for. Thanks!
     
  13. EcComicFan

    EcComicFan

    Joined:
    Sep 11, 2016
    Posts:
    7

    Wow, can't believe I missed the Unity 5 Update guide underneath the videos. It's a huge help! (Though I might suggest some check out the update info for 3 - Camera and Lighting before starting the project.) Still, there's no mention of the Web Player vs WebGL issue. Any clarity on that would still be appreciated!!!
     
    WilliamKus likes this.
  14. irishdjali

    irishdjali

    Joined:
    Sep 11, 2016
    Posts:
    5
    @Adam-Buckner I'm running into an issue right off the bat. I have Unity 5. The first lesson says to select Web Player as the platform, but I don't have that option. Is it Web GL in Unity 5 instead? And if so, how do you change the resolution? And if not, what am I missing?
     
    WilliamKus likes this.
  15. irishdjali

    irishdjali

    Joined:
    Sep 11, 2016
    Posts:
    5
    The DONE PlayerController code doesn't match the code on the tutorial page (Lesson 5), which I would expect.

    However... neither does it match the Unity 5 Upgrade Guide. And I am having all sorts of problems with the Rigidbody code, especially since the guide makes suggested changes but then doesn't address the "movement" variable which no longer exists, based on what they say a line should read.

    And I ignore that and use the GetComponent<Rigidbody>() inline as the Unity editor and the Done script show, while I get no errors and I can "Play" the game, the Player ship doesn't actually move.
     
  16. justsoelmo

    justsoelmo

    Joined:
    Sep 16, 2016
    Posts:
    5
    So, my enemy ships are spawning backward and not moving down the screen. They shoot, tilt, etc., but they don't move toward me. Here's my maneuvering code:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class EvasiveManeuver : MonoBehaviour
    5. {
    6.  
    7.     public float dodge;
    8.     public float smoothing;
    9.     public float tilt;
    10.     public Vector2 startWait;
    11.     public Vector2 maneuverTime;
    12.     public Vector2 maneuverWait;
    13.     public Boundary boundary;
    14.  
    15.     private float currentSpeed;
    16.     private float targetManeuver;
    17.     private Rigidbody rb;
    18.  
    19.     [System.Serializable]
    20.     public class Boundary
    21.     {
    22.         public float xMin, xMax, zMin, zMax;
    23.     }
    24.  
    25.     void Start()
    26.     {
    27.         rb = GetComponent<Rigidbody>();
    28.         currentSpeed = rb.velocity.z;
    29.         StartCoroutine(Evade());
    30.     }
    31.  
    32.     IEnumerator Evade()
    33.     {
    34.         yield return new WaitForSeconds(Random.Range(startWait.x, startWait.y));
    35.  
    36.         while (true)
    37.         {
    38.             targetManeuver = Random.Range(1, dodge) * -Mathf.Sign(transform.position.x);
    39.             yield return new WaitForSeconds(Random.Range(maneuverTime.x, maneuverTime.y));
    40.             targetManeuver = 0;
    41.             yield return new WaitForSeconds(Random.Range(maneuverWait.x, maneuverWait.y));
    42.         }
    43.     }
    44.  
    45.     void FixedUpdate()
    46.     {
    47.         float newManeuver = Mathf.MoveTowards(rb.velocity.x, targetManeuver, Time.deltaTime * smoothing);
    48.         rb.velocity = new Vector3(newManeuver, 0.0f, currentSpeed);
    49.         rb.position = new Vector3
    50.         (
    51.             Mathf.Clamp(rb.position.x, boundary.xMin, boundary.xMax),
    52.             0.0f,
    53.             Mathf.Clamp(rb.position.z, boundary.zMin, boundary.zMax)
    54.         );
    55.  
    56.         rb.rotation = Quaternion.Euler(0.0f, 0.0f, rb.velocity.x * -tilt);
    57.     }
    58. }
    As you can see, I had to change the Boundary so that it included a serializable class. It kept coming up with errors if I didn't. Any ideas?
     
    Last edited: Sep 21, 2016
  17. Technomancer999

    Technomancer999

    Joined:
    Sep 22, 2016
    Posts:
    1
    I'm actually having difficulty at "Setting up the Project". I am using the new current version of Unity (5.4.1f1) which seems to provide different results, the view did not automatically give me a game view, only 2 scene views from different angles... but when I switched to WebGL (Web Player is not in this version) There was no option under the dropdown menu to set view to the (Web) player option, it only had the preset ratios. Is there a different method for this process concerning this version, or alternatively how can I set it so it does default to the settings shown in the video?
     
    WilliamKus likes this.
  18. Aj8

    Aj8

    Joined:
    Jun 12, 2016
    Posts:
    1
    Hi there, sorry if my english is bad but i have problem with this "Application.LoadLevel (Application.loadedLevel);" its obsolit so can u tell me how to change that
     
    TaylorFlorian likes this.
  19. EcComicFan

    EcComicFan

    Joined:
    Sep 11, 2016
    Posts:
    7
    So, I've made my way through the main tutorial with minimal problems, but now I'm an hour and a half into the enemy ships portion and I'm all a mess. I've typed out the code precisely as instructed (with the exception of having to implement Scene Management) and my enemy ships aren't spawning correctly. They spawn about two thirds of the way down the screen and do move along the -z axis. They still maneuver and fire shots, but they just move back and forth along the x axis. Any thoughts? I'm really at a loss.
     
  20. EcComicFan

    EcComicFan

    Joined:
    Sep 11, 2016
    Posts:
    7
    I had this problem.

    At the top of your GameController script add:

    using UnityEngine.SceneManagement;

    then, on line 38, replace:

    Application.LoadLevel (Application.loadedLevel);

    with:

    SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);


    That should do the trick ;)
     
  21. WingedOne

    WingedOne

    Joined:
    Jul 27, 2016
    Posts:
    7
    When building the game for the web player it says "Development Build" on the bottom right of the screen whether I have Development Build checked or unchecked in the build settings.

    Any ideas?
     
  22. spounyboy

    spounyboy

    Joined:
    Aug 18, 2015
    Posts:
    5
    Hi
    I just finished the Tutorial and I have some questions.
    First, can you put ouline and shadows on a GUItext (I tried and nothing happened).
    Secondly I have a sound problem, everything is working except the Asteroid explosion sound.
    I also have a problem to configure a joystick, it's working but the ship go stray on the upper left corner, I can control it (somehow) and shoot stuf but the ship is attracted to the upper left corner.
    Just so you know, I don't have any issue with the keyboard. Any Idea ? bad controller ? (it's a Thrusmaster Dual Analog 4
    Finally I would like to know how can I had an objective (like a certain amount of target to destroy) and a "YOU WIN" screen when the player achieve the objective.
    Thanks
     
    Last edited: Sep 26, 2016
  23. Tahira_Kauser

    Tahira_Kauser

    Joined:
    Sep 27, 2016
    Posts:
    1
    I am unable to drag and drop vehicle_player_ship to main heirarchy; assets in Model folder are not enabled even
     

    Attached Files:

  24. MoZax

    MoZax

    Joined:
    Sep 29, 2016
    Posts:
    1
    Hi. i am so good so far. done roll ball game. but stuck at space shooter. My issue is that the asteroid is not moving towards the player.

    my codes are
    Actually named as Mover in original Project.
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class boltcontroller : MonoBehaviour {
    5.  
    6.     public float speed;
    7.  
    8.         void Start ()
    9.         {
    10.         GetComponent<Rigidbody>().velocity = GetComponent<Rigidbody>().transform.forward * speed;
    11.         }
    12.     }
    For Rotator
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class rotator : MonoBehaviour {
    5.         // Update is called once per frame
    6.  
    7.     void Update () {
    8.         transform.Rotate (new Vector3 (30, 45, 60)* Time.deltaTime *5);
    9.  
    10.     }
    11.  
    12. }
    13.  
    and for Destroybycontact

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class destroybycontact : MonoBehaviour {
    5. //    public float speed;
    6.     public GameObject explosion;
    7.     public GameObject playerexplosion;
    8.     void OnTriggerEnter(Collider other) {
    9.         if (other.tag == "Boundary") {
    10.             return;
    11.  
    12.         }
    13.         Instantiate (explosion, transform.position, transform.rotation);
    14.         if (other.tag == "Player") {  
    15.             Instantiate (playerexplosion, other.transform.position, other.transform.rotation);
    16.  
    17.  
    18.         }
    19.         Destroy(other.gameObject);
    20.         Destroy (gameObject);
    21.  
    22.         }
    23.  
    24.  
    25. }
    26.  
    Any help is highly appreciated thanks.

    edit: i am using 5.4.1f
     
  25. Eirtlin

    Eirtlin

    Joined:
    Sep 30, 2016
    Posts:
    2
    Hi all.
    I'm following the chapter 05 "moving the player" and it's all ok untill i set the min, max value for bonduary. I have followed the script, but when my ship arrive at boundary, it doesn't stop there. It's like the ship softly stop, but if i continue press in that way, the ship continue go over the bounday, in a very slow way. Otherwise, if i press in any other direction, opposite too, it take some time to move, like it's been blocked from something (like she was in a swamp... i don't know how better explain). I hope my explanation is clear enough, and sorry for my bad english :rolleyes:
     

    Attached Files:

  26. Eirtlin

    Eirtlin

    Joined:
    Sep 30, 2016
    Posts:
    2
    Sorry, wrong way to insert code. Here it is!

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. [System.Serializable]
    5. public class Boundary
    6. {
    7.     public float xMin, xMax, zMin, zMax;  
    8. }
    9.  
    10. public class PlayerController : MonoBehaviour
    11. {
    12.     private Rigidbody rb;
    13.  
    14.     public float speed;
    15.     public Boundary boundary;
    16.  
    17.     void Start()
    18.     {
    19.         rb = GetComponent<Rigidbody> ();
    20.     }
    21.     void FixedUpdate ()
    22.     {
    23.         float moveHorizontal = Input.GetAxis ("Horizontal");
    24.         float moveVertical = Input.GetAxis ("Vertical");
    25.  
    26.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    27.         rb.AddForce (movement * speed);
    28.  
    29.         rb.position = new Vector3
    30.         (
    31.             Mathf.Clamp (rb.position.x, boundary.xMin, boundary.xMax),
    32.             0.0f,
    33.             Mathf.Clamp (rb.position.z, boundary.zMin, boundary.zMax)
    34.         );
    35.     }
    36. }
    37.  
     
  27. CoranTheSilver

    CoranTheSilver

    Joined:
    Sep 25, 2016
    Posts:
    5
    So... I know this is an above and beyond thing but I feel like it is important to learn. After adding the Quaternion.Euler, my ship does a beautiful rotation when I go left or right. How do I go about making the rotation smooth when I change directions as opposed to resetting rotation to 0 and then rotating? I fiddled around with slerp but I don't have the experience with C# to do it properly.

    Can I do something in the Euler?
    Code (csharp):
    1.  
    2. rb.rotation = Quaternion.Euler(rb.velocity.z * tilt / 2, 0.0f, rb.velocity.x * -tilt);
    3.  
     
  28. CoranTheSilver

    CoranTheSilver

    Joined:
    Sep 25, 2016
    Posts:
    5
    The only difference I could find is on line 27

    rb.AddForce (movement * speed);

    I am using velocity and it works great. everything else is identical.

    rb.velocity = movement * speed;

    Using velocity also lets you use the tilting recommended later in the tutorial.
     
  29. CoranTheSilver

    CoranTheSilver

    Joined:
    Sep 25, 2016
    Posts:
    5
    Post your scripts
     
  30. zach123

    zach123

    Joined:
    Oct 1, 2016
    Posts:
    3
    Hi,
    WebGL resolution problems - cant change resolution.
    i am stuck like many others on Tutorial 1 - setting up the Project. I have read about 10 other people who are having issues with the WebGL resolution. Like the others, I have installed WebGL and change the resolution as the tutorial says, but under the Game View there is no option to choose the recomended resolution of 600/900. WebGL does not appear at all as an option under the Game View dropdown.. Its meant to appear when you make WebGL the platform.... please help us. waaah.
     
    WilliamKus likes this.
  31. zach123

    zach123

    Joined:
    Oct 1, 2016
    Posts:
    3
    Im stuck here as well, its killing me. i posted it as a question as well...
     
    WilliamKus likes this.
  32. scooterboy

    scooterboy

    Joined:
    Oct 1, 2016
    Posts:
    5
    You need to click on the drop down menu with all the sizes, then click on the + sign and enter in 600x900. You can also put a label like I did called Vertical.
    Once you're done, select the aspect ratio you just created. This is how it looks on my Unity editor - Create new size.JPG
     
    kgalea, nedgip, Skyho and 1 other person like this.
  33. scooterboy

    scooterboy

    Joined:
    Oct 1, 2016
    Posts:
    5
    I'm stuck in 1.5 - Moving the Player (around 6:40).
    My player GameObject doesn't seem to move at all when I enter play mode. I've checked to see if there's any typos or discrepancies in the code, but I couldn't find any. The player object just stays fixed in its original location. Any ideas why?

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PlayerController : MonoBehaviour
    5. {
    6.     private Rigidbody rb;
    7.  
    8.     void Start ()
    9.     {
    10.         rb = GetComponent<Rigidbody>();
    11.     }
    12.  
    13.     void fixedUpdate()
    14.     {
    15.         float moveHorizontal = Input.GetAxis ("Horizontal");
    16.         float moveVertical = Input.GetAxis ("Vertical");
    17.  
    18.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    19.  
    20.         rb.velocity = movement;
    21.     }
    22. }
     
  34. scooterboy

    scooterboy

    Joined:
    Oct 1, 2016
    Posts:
    5
    OK. So I figured it out what was going wrong.

    I wrote in line 13 -
    void fixedUpdate()

    It should have been
    void FixedUpdate()

    One letter that wasn't in caps gave me 1 hour of trouble. Computers man.
     
  35. zach123

    zach123

    Joined:
    Oct 1, 2016
    Posts:
    3
    thanks thats awesome. fixed it now i can continue. cheers
     
  36. z3

    z3

    Joined:
    Jun 3, 2016
    Posts:
    34
    Wondering if anyone can help me ,I went through the extending to mobile video and its not working on my phone I can fire but I can't move.
    is there anything thats changed in unity 5 since that tutorial besides me having to change the ridgidbodys to the getcomponent stuff??

    thanks
     
  37. westergard

    westergard

    Joined:
    May 4, 2015
    Posts:
    90
    Hello,

    i made some modifications to the script for the playercontroller and tried to add the laser directly in that script... Can anyone check up on it to see if everything seems fine or i'm making it too complicated?

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PlayerC : MonoBehaviour {
    5.  
    6.     public Rigidbody rb;
    7.     public float spd;
    8.     public GameObject laser;
    9.     private string side;
    10.     private bool xlimit; // n = negative
    11.     private bool nxlimit;
    12.     private bool zlimit;
    13.     private bool nzlimit;
    14.     private bool canCall;
    15.  
    16.     IEnumerator tiltShip()
    17.     {
    18.         canCall = false;
    19.         transform.rotation = Quaternion.Lerp (transform.rotation, transform.rotation, Time.deltaTime);
    20.         yield return new WaitForSeconds (5f);
    21.         canCall = true;
    22.     }
    23.  
    24.     void Start ()
    25.     {
    26.         rb = GetComponent<Rigidbody> ();
    27.         canCall = true;
    28.         zlimit = false;
    29.         nzlimit = false;
    30.         xlimit = false;
    31.         nxlimit = false;
    32.     }
    33.  
    34.     void Update()
    35.     {
    36.         if (canCall == true)
    37.         {
    38.             StartCoroutine (tiltShip ());
    39.         }
    40.  
    41.         float xa = Input.GetAxis ("Horizontal");
    42.         float za = Input.GetAxis ("Vertical");
    43.         if (xa > 0) {
    44.             side = "left";
    45.         } else if (xa < 0) {
    46.             side = "right";
    47.         } else if (xa == 0)
    48.         {
    49.             side = "none";
    50.         }
    51.  
    52.  
    53.         if (transform.position.x > 2.5f) {
    54.             //transform.position = transform.position - new Vector3 (0.1f, 0, 0);
    55.             xlimit = true;
    56.         } else
    57.         {
    58.             xlimit = false;
    59.         }
    60.         if (transform.position.x < -2.5f) {
    61.             //transform.position = transform.position - new Vector3 (-0.1f, 0, 0);
    62.             nxlimit = true;
    63.         } else {
    64.             nxlimit = false;
    65.         }
    66.         // __________________ //
    67.         if (transform.position.z > 7f) {
    68.             //transform.position = transform.position - new Vector3 (0.1f, 0, 0);
    69.             zlimit = true;
    70.         } else
    71.         {
    72.             zlimit = false;
    73.         }
    74.         if (transform.position.z < 0f) {
    75.             //transform.position = transform.position - new Vector3 (-0.1f, 0, 0);
    76.             nzlimit = true;
    77.         } else {
    78.             nzlimit = false;
    79.         }
    80.  
    81.         if (xlimit == true || nxlimit == true)
    82.         {
    83.             transform.rotation = Quaternion.Euler (0, 0, 0);
    84.             print ("ok");
    85.         }
    86.         else
    87.             if (xlimit == false || nxlimit == false)
    88.             {
    89.                 transform.rotation = Quaternion.Euler (za*6, 0, xa*6);
    90.             }
    91.         //_________________//
    92.         if (zlimit == true || nzlimit == true)
    93.         {
    94.             transform.rotation = Quaternion.Euler (0, 0, 0);
    95.             print ("ok");
    96.         }
    97.         else
    98.         if (zlimit == false || nzlimit == false)
    99.         {
    100.                 transform.rotation = Quaternion.Euler (za*6, 0, xa*6);
    101.         }
    102.         //transform.rotation = transform.rotation + Quaternion.Euler (0, rot, 0);
    103.  
    104.         if (Input.GetKeyDown (KeyCode.Space))
    105.         {
    106.             var l = Instantiate (laser, transform.position, Quaternion.Euler(90f,0,0));
    107.         }
    108.  
    109.  
    110.         print ("n: " + nxlimit + " p: " + xlimit);
    111.     }
    112.  
    113.     void LateUpdate ()
    114.     {
    115.         float xa = Input.GetAxis ("Horizontal");
    116.         float za = Input.GetAxis ("Vertical");
    117.         /*if (za < 0 & nxlimit == true || za > 0 & zlimit == true)
    118.         {
    119.             za = 0;
    120.         }*/
    121.         if (za < 0 & nzlimit == true || za > 0 & zlimit == true) {
    122.             za = 0;
    123.         } else {
    124.             za = Input.GetAxis ("Vertical");
    125.         }
    126.  
    127.         if (xa < 0 & nxlimit == true || xa > 0 & xlimit == true) {
    128.             xa = 0;
    129.         } else {
    130.             xa = Input.GetAxis ("Horizontal");
    131.         }
    132.  
    133.         rb.velocity = new Vector3 (xa * spd, 0, za*spd);
    134.  
    135.         /*if (xa < 0 & nxlimit == true || xa > 0 & xlimit == true) {
    136.             rb.velocity = new Vector3 (0, 0, za * spd);
    137.         } else {
    138.             rb.velocity = new Vector3 (xa * spd, 0, za*spd);
    139.         }*/
    140.     }
    141. }
    142.  
    thanks so much for your help

    seb
     
  38. Deleted User

    Deleted User

    Guest

    Add all 43 images to your assets.
    If all 43 images are part of same animation open up animation window by going to the menu bar > Window > Animation.
    Then select the create animation button and pick name for animation and save. then select the 43 assets and drag and drop into animation window. You know have an animation that can be edited. If you don't have one already added you'll need to create an animator controller but that should be automatically added if you don't have one already.
    Depending on the setup you may or may not have In your code you'll have a reference to the asteroid object. Once the asteroid is destroyed instantiate the plane and call the animation, base the starting rotation off the destroyed asteroid object. If the explosion picture is symetrical, you're not going to notice a difference . since we're using 3d space from the top down, if its rotated the wrong way the animation will be present, just not visible because the sprite will be a flat 2d dimension. You actually shouldn't need a plane. The empty game object should suffice with the animation. I'll try to remember to do an example and post in coming days, I don't quite understand what you're asking for part 4 though
     
  39. Deleted User

    Deleted User

    Guest

    This is what I had from several months ago so you look fine.
    GetComponent<Rigidbody>().angularVelocity = Random.insideUnitSphere * tumbleSpeed;
    I'd check to make sure you added the script to the game object. If you needed to add the rigidbody you would get an error message saying you need to create a reference... so i'm thinking you didn't add the script to the game object.
     
  40. Deleted User

    Deleted User

    Guest

    I didn't look at the code closely, but the tutorial for the sleepy shooter gets into raycasting that has more of a laser effect.
    Basically it uses a ray to detect where object at then fires at angle. Another alternative is I believe the Quaternion/rotations have a lookattarget function where you could actually setup the initial bolt at angle then release "forward". There's also nothing to say that you couldn't use a target transform as a reference then send the laser/bolt on a trajectory toward that reference point, that would probably use some lerp type of transformation.
     
  41. mohithkalyan

    mohithkalyan

    Joined:
    Oct 5, 2016
    Posts:
    1
    I have sound issues with the audio clips. They are doing good when played in a music player but, when I click on the play button in the preview which is in the bottom of the inspector, It does nothing. Although I wrote the code for audio clips, I didn't hear anything in the game mode. Can anyone help me out ? Thanks in advance.
     
  42. TeamFatal

    TeamFatal

    Joined:
    Oct 6, 2016
    Posts:
    2
    I'm sorry if someone has already ran into and asked about this issue but does anyone understand why when moving forward or backwards (along z axis) the bolts spawn and then despawn about a second later. I've tested to be sure if they come in contact further up the screen or not and they don't. Also moving the bullets further back or further forward (moving the shot spawn) doesn't change anything. It's time to walk a way for a bit for the night and so I figured I'd give it overnight to wait and see if someone has been bothered by this as bad as I have. Thank you ahead of time.
     
  43. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Have a little look to see if 'Use Gravity' is ticked on the rigidbody attached to the bolt. if it is, deselect it.
    If gravity is enabled, as it moves forward, it will drop and eventually leave the boundary a second or so after being fired.

    you say, that its happening with moving forward and back, does it exhibit the same thing when moving player left and right, and stationary?
     
  44. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    just wondering, is it windows you are running?
    have you tried closing project, and opening a new default project to see if that plays any audio?

    also when unity is open, if it is windows, right click your speaker icon in taskbar and open volume mixer, and check that windows hasnt muted Unity application audio.
     
  45. TeamFatal

    TeamFatal

    Joined:
    Oct 6, 2016
    Posts:
    2
    Use gravity isn't checked and no it does not do this when stationary or moving left and right. But I think I just figured out why as I was typing this. :p it's because of a piece of code I added when we make the ship tilt. I thought it be cool is the ship tilted forward and back and never removed it when I realized how unrealistic it felt if I was to tilt forward but move along the same line. Sorry to have bugged you about this when it was my fault.
     
    Last edited: Oct 7, 2016
  46. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    not a problem at all, its all part of the learning :)

    fantastic that you managed to get it running, but now you know what it was doing, you got it sorted! so its all good.
    never be sorry for asking questions, that's what were all here for ;)
     
  47. CNate

    CNate

    Joined:
    Oct 12, 2016
    Posts:
    2
    Sorry to criticize something with my first and maybe only post, but you might want to add that Web Player is no longer in use and it's preferred to use WebGL now for the tutorial in the upgrade guide for 01. Setting up the project. It caused a little confusion for me since I prefer explicit information.
     
  48. foffles105

    foffles105

    Joined:
    Sep 29, 2016
    Posts:
    1
    This is my first time using the forums.

    Everything has been going fine as far as creating the game until i got to the movement. I keep getting an error saying

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

    I am pretty new to unity and know very little what it means.

    here's the code

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. [System.Serializable]
    5. public class  Boundary
    6. {
    7.     public float xMin, xMax, zMin, zMax;
    8. }
    9. public class PlayerController : MonoBehaviour
    10. {
    11.     private Rigidbody Rigidbody;
    12.  
    13.     public float speed;
    14.     public float tilt;
    15.     public Boundary boundary;
    16.  
    17.  
    18.  
    19. void FixedUpdate ()
    20.     {
    21.         float moveHorizontal = Input.GetAxis ("Horizontal");
    22.         float moveVertical = Input.GetAxis ("Vertical");
    23.  
    24.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    25.         Rigidbody.velocity = movement * speed;
    26.  
    27.         Rigidbody.position = new Vector3
    28.             (
    29.                 Mathf.Clamp (Rigidbody.position.x, boundary.xMin, boundary.xMax),
    30.                 0.0f,
    31.                 Mathf.Clamp (Rigidbody.position.z, boundary.zMin, boundary.zMax)
    32.             );
    33.         Rigidbody.rotation = Quaternion.Euler (0.0f, 0.0f, Rigidbody.velocity.x * -tilt);
    34.     }
    35. }
    36.  
     
  49. CNate

    CNate

    Joined:
    Oct 12, 2016
    Posts:
    2
    It's because you never got the RigidBody component for the player object. You do this by typing

    Code (csharp):
    1.  
    2. Rigidbody rb = GetComponent<Rigidbody>();
    3.  
    then use rb.velocity to assign the velocity. Also since rb is a variable, you can use any other name though I don't advise using a variable name "Rigidbody" since that will only confuse you later and might not even be allowed by Unity.

    Edit: this is also if you are using 5.x Unity. Which I believe you are since you were trying to get the Rigidbody component
     
  50. A_Savvidis

    A_Savvidis

    Joined:
    Jul 21, 2016
    Posts:
    98
    If you see asteroids keep vanishing there are two ways to fix it :
    1. Enlarge the container that deletes everything tha leaves the screen in the Y axis or
    2. Have this code in the random rotator script :

    Code (CSharp):
    1.     void FixedUpdate ()
    2.     {
    3.         rb.velocity = new Vector3(0.0f ,0.0f ,-3.7f);
    4.     }
    (or use a variable instead of -3.7f)