Search Unity

2D UFO Tutorial Q&A

Discussion in 'Community Learning & Teaching' started by Matthew-Schell, Jan 22, 2016.

  1. Kyle_Kosh

    Kyle_Kosh

    Joined:
    Mar 8, 2016
    Posts:
    2
    Hi,

    Great tutorial thank you!

    I'm scratching my head over something... the Win Text component in Unity's Game View appears in a different place (develop or play mode) compared to what gets shown in the compiled version (and also what is shown in the video) when using the value for the y co-ordinate as 75.

    My view in Unity shows Win Text up near the top of the gameboard (about 1 square down) when I set the y-co-ordinate to 75 but... in the video and in my compiled version, the text appears a lot closer to the Player object (see screenshots below).

    I've tried resetting the Win Text component using the widget in the top-right and have also tried copying all of the values for width, height, pivot, anchors etc for the Win Text object from the tutorial video but I still get this weird discrepancy.

    Any ideas? I'm sure I'm just doing something stupid, but it's really bugging me as I won't know how to place things in dev mode without compiling everything first to check where things get placed!

    I have attached screenshots for both the game view and the compiled version so you can see the difference in placement for Win Text - also you will see that the text seems bigger in the Game View.

    By the way I'm using:
    Version 5.3.3f1 Personal
    (...on a pc notebook running Windows 10 Home)

    Cheers
    gameview.jpg compiledversion.jpg
     
    Last edited: Mar 8, 2016
  2. PeasOfMind

    PeasOfMind

    Joined:
    Mar 10, 2016
    Posts:
    1
    What script editor were you using? Thanks!
    P.S. I posted the question of YouTube but then noticed the forum link to here, so I apologize for the spam.
     
  3. Kyle_Kosh

    Kyle_Kosh

    Joined:
    Mar 8, 2016
    Posts:
    2
    MonoDevelop (not sure what spam you're referring to as this is the only reply I've seen bud)
     
  4. Samson_Superlug

    Samson_Superlug

    Joined:
    Oct 15, 2013
    Posts:
    5
    Help needed please, ive just created my PlayerController script and it didnt com back with any errors, ive changed the gravity of my Rigidbody 2d to 0 and when i test the game nothing happens no moment from the UFO at all

    HELP
     
  5. Marcel_Stiefel

    Marcel_Stiefel

    Joined:
    Mar 14, 2016
    Posts:
    1
    Hi there,

    absolute beginner- I can't even see where to click on "Download assets" for the 2d UFO tutorial
     
  6. Matthew-Schell

    Matthew-Schell

    Joined:
    Oct 1, 2014
    Posts:
    238
    I haven't seen that issue before. What version of Unity are you running? And what platform were you building to?
     
  7. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Have a quick look in your player controller script, just to make sure that the FixedUpdate() method is capitalised in the correct way, otherwise it wont error, it just wont get called and thereby will not be getting or applying the input.

    Code (CSharp):
    1. void FixedUpdate()
    and maybe check that the 'is Kinematic' is unchecked, as having this ticked will not allow your movement forces to be applied to the Rigidbody of your player.

    Just a couple of thoughts. see how you get on with this.
     
    Matthew-Schell likes this.
  8. Matthew-Schell

    Matthew-Schell

    Joined:
    Oct 1, 2014
    Posts:
    238
    Upon further research it seems that this is a result of the default UI shader being missing from the list shown here:

    http://docs.unity3d.com/Manual/class-GraphicsSettings.html

    This is a list of the always included shaders in a build. Can you check that list and make sure that the shader is included? Was there something unique about how this project was created?
     
  9. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Evening, should be in the asset store, in the editor 'Window > Asset store' under the unity essentials heading on the right
    https://www.assetstore.unity3d.com/en/#!/content/52143
     
    Matthew-Schell likes this.
  10. Sembler

    Sembler

    Joined:
    Mar 23, 2016
    Posts:
    2
    Everything goes great for me until I build the game and run it. I changed some things for my version of the game, such as color and pickup placement, but when I build and run, the game is exactly like the original demo version in the video. Any thoughts as to how this could happen?
     
  11. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    When you go to build the game, ensure that your scene that you made the changes in is in the build settings.
    if in doubt, when you have your version of the scene open, when you go to build, remove the scene in the list and add open scenes, then try building. Just a thought, see if that works. I cant put up and screenshots or exact working of the window as im not at my PC just now.
     
    Matthew-Schell and Sembler like this.
  12. Sembler

    Sembler

    Joined:
    Mar 23, 2016
    Posts:
    2
    That did it! Thanks for the reply.
     
    OboShape and Matthew-Schell like this.
  13. DahevosCN

    DahevosCN

    Joined:
    Mar 27, 2016
    Posts:
    1
    Thanks for this tutorial, very well explained.
     
    Matthew-Schell likes this.
  14. 8Raj89

    8Raj89

    Joined:
    Feb 28, 2016
    Posts:
    1
    Hi guys, first of all thanks a lot for taking the effort to make such an amzing tutorial to help beginners like me.

    My problem is that the ufo does not move when i hit play and press the arror keys. I even copy-pasted the same code as provided in the instructors instructions below the video, but the problem still persists.I went through the entire forumbut couldnt find an helpful answer
    It would mean a lot to me if someone could help me out here, I ll be eagerly awaiting a reply.
    Thankyou
     
  15. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Morning @8Raj89,

    Just wondering, are you getting any errors showing in the console when you press play, or when you press the arrow keys?

    Sometimes, its worth having a double check that the objects in your scene and their properties in the inspector are the same as what are shown by the instructor. For instance check that the Rigidbody2D that you have attached to the player, had the 'Is Kinematic' unchecked, have you added a speed value in the inspector?
    Also have a check that you have attached the player controller script to the player object.

    Might be worth another watch through of the 'Controlling the player' video, just to double check what Matt has in the inspector compared to what you have in your project.
    http://unity3d.com/learn/tutorials/projects/2d-ufo-tutorial/controlling-player?playlist=25844

    I think theres also a 'Completed' folder within the project, that you can compare with also.
     
    Matthew-Schell likes this.
  16. Matthew-Schell

    Matthew-Schell

    Joined:
    Oct 1, 2014
    Posts:
    238
    hey @8Raj89 OboShape has given you some good tips there, maybe you could post a screenshot of the inspector with the player highlighted? I'm assuming the problem will be there if you already copied and pasted the scripts.
     
    OboShape likes this.
  17. shrtylu

    shrtylu

    Joined:
    Apr 9, 2016
    Posts:
    2
    when I click on the asset page "open in unity nothing happens"
     
  18. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Have you tried opening the Asset Store from within Unity editor to see if that works?

    In the menu, click on Window > Asset Store
     
    Matthew-Schell likes this.
  19. Rockyeahh

    Rockyeahh

    Joined:
    May 19, 2016
    Posts:
    17
    Hey I just finished part 5 of the 2D UFO tutorial but for some reason my player no longer moves properly. They only move to the top right corner or back down to the bottom left corner. I checked the scripts and they are correct. I rewatched the last few tutorials to see if I missed something but nothing was missing. :( It also doesn't roll off of the walls or anything, just moving between those two corners.
     
  20. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Any chance you can post your player controller script please. Would you be able to post a screenshot of the editor, showing the inspector when the player is highlighted please.

    Just wondering, have you detached the main camera so that its no longer a child of the player?
     
  21. Rockyeahh

    Rockyeahh

    Joined:
    May 19, 2016
    Posts:
    17


    I did detach the camera from the player.

    upload_2016-5-19_16-2-29.png

    And this is the script. :)

    using UnityEngine;
    using System.Collections;

    public class PlayerController : MonoBehaviour {

    public float speed;

    private Rigidbody2D rb2d;

    void Start()
    {
    rb2d = GetComponent<Rigidbody2D> ();
    }

    void FixedUpdate()
    {
    float moveHorizontal = Input.GetAxis ("Horizontal");
    float moveVertical = Input.GetAxis ("Horizontal");
    Vector2 movement = new Vector2 (moveHorizontal, moveVertical);
    rb2d.AddForce (movement * speed);
    }
    }
     
  22. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Evening,

    Looking at your script, for grabbing the input of the keyboard, you are setting both axis to Horizontal, thereby getting only diagonal movement in the game when you test it.

    Need to change your code:
    Code (CSharp):
    1. float moveHorizontal = Input.GetAxis ("Horizontal");
    2. float moveVertical = Input.GetAxis ("Horizontal");
    to this

    Code (CSharp):
    1. float moveHorizontal = Input.GetAxis ("Horizontal");
    2. float moveVertical = Input.GetAxis ("Vertical");
    should be good to go ;)
     
    Last edited: May 20, 2016
    Matthew-Schell likes this.
  23. Rockyeahh

    Rockyeahh

    Joined:
    May 19, 2016
    Posts:
    17

    Ohh I'm such a fool. Thank you! :)
     
  24. Hacktivista

    Hacktivista

    Joined:
    May 24, 2016
    Posts:
    3
    In video 1, minute 2:37 he says ""For more information on working in 2D, please see the information linked below", but I can't find the link.

    I see that this happens more than once, maybe you should check that.
     
    Last edited: May 25, 2016
  25. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Not at my pc at the moment, but he could be directing you to the 2D section of the learn site, theres loads of 2D lessons and info there.
    http://unity3d.com/learn/tutorials/topics/2d-game-creation
     
  26. Hacktivista

    Hacktivista

    Joined:
    May 24, 2016
    Posts:
    3
    Why we rotate using
    Code (csharp):
    1. new Vector3(0,0,45)*Time.deltaTime
    instead of
    Code (csharp):
    1. new Vector3(0,0,1)
    for example?
     
  27. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Morning,

    This is is the rotator script for the pickups?

    transform.Rotate() has several different overloads, which boils down to it can behave differently based on what arguments you pass in between the braces ( ).
    http://docs.unity3d.com/ScriptReference/Transform.Rotate.html

    in this instance we are passing in one Vector3 value. so Rotate will use each of the X, Y, Z parts of the Vector3 value to rotate that amount of degrees around the axis each frame.

    Since transform.Rotate() is called on each Update, this is called every frame.

    so
    Code (CSharp):
    1. transform.Rotate(new Vector3(0,0,1));
    this would rotate the object 1 degree on the Z axis each frame.

    Time.deltaTime is the time in seconds in between update calls. (this is normally quite small,

    when you use the following
    Code (CSharp):
    1. transform.Rotate (new Vector3 (0, 0, 45) * Time.deltaTime);
    this says that we want to rotate a fraction of 45 degrees proportional to the time in seconds it takes to call each update, so effectively giving us 45 degrees rotation on the Z axis each second.
    you can see more on Time.deltaTime here
    http://unity3d.com/learn/tutorials/topics/scripting/delta-time?playlist=17117

    Its a fair bit to take in just now, hope that helps slightly.
     
    Matthew-Schell likes this.
  28. Larrson2014

    Larrson2014

    Joined:
    Jun 8, 2016
    Posts:
    2
    HI I have an error and I do not see what is wrong

    This is my script
    ----------------------------------------------------------------------------------------------------------------------------------------------------------------
    using UnityEngine;
    using System.Collections;

    public class PlayerController : MonoBehaviour (

    private Rigidbody2D rb2d:

    void start()
    (
    rb2d = GetComponent<Rigidbody2D> ():
    )


    void FixedUpdate ()
    (
    float moveHorizontal = input.GetAxis ("Horizontal"):
    float moveVertical =input.GetAxis ("vertical"):
    Vector2 movement = new vector2 (movementHorizontal, move vertical):
    rg2d.AddForce (movement):
    )
    )
    ----------------------------------------------------------------------------------------------------------------------------------------------------------------
    This is my error
    ----------------------------------------------------------------------------------------------------------------------------------------------------------------
    There is no MonoBehaviour scripts in the file, or their names do not match the file name.
    ----------------------------------------------------------------------------------------------------------------------------------------------------------------
    PLEASE HELP!!!!!
     
  29. mattdevelopment01

    mattdevelopment01

    Joined:
    Jun 8, 2016
    Posts:
    1
    Hi,
    I've done everything exactly like the video, and when I go to Unity from MonoDevelop, I get an error saying, "MissingReferenceException: THe object of type 'Object' has been destroyed but you are still trying to access it.". Also, when I go to edit my script, MonoDevelop says that it cannot open the project because of an unknown item type. Finally, it also tells me that I have "line endings(UNIX) which differ from the policy settings"
    Please Help!
     
  30. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Morning,

    Had a quick look, but I'm currently offshore and don't have pc access. But..

    Your Start method should have a capital 'S', otherwise it wont get called.

    In your FixedUpdate, when assigning the movement Vector2, the arguments you pass in should be 'moveHorizontal' and 'moveVertical' as these are what you are declaring in the two lines above it.

    Where you are applying the force you have written 'rg2d' instead of 'rb2d'.

    Ensure that your class name at the top of the script matches exactly the filename of your script, then try removing the script from your player and readding it in the inspector.

    Again, sorry I've only got access via my phone, hope u get on ok
     
  31. Matthew-Schell

    Matthew-Schell

    Joined:
    Oct 1, 2014
    Posts:
    238
    OboShape is correct (thanks man!). The line endings is a non-issue, just choose 'convert'. Fix the errors in your script and let us know if that helps.
     
  32. Tovey-Ansell

    Tovey-Ansell

    Joined:
    Jul 8, 2015
    Posts:
    150
    Baffled as to why this won't work, here's my code, any help would be super appreciated, this doesn't seem to work regardless of what I've set speed to..


    public class PlayerController : MonoBehaviour
    {
    public float speed;
    private Rigidbody2D rb2d; //Must be RB2d, not RB!!


    // Use this for initialization
    void Start()
    {
    rb2d = GetComponent<Rigidbody2D>();
    Debug.LogWarning("TEST START");
    }

    // Update is called once per frame
    void FixedUpdate()
    {
    Debug.LogWarning("TEST");
    float moveHorizontal = Input.GetAxis("Horizontal");
    float moveVertical = Input.GetAxis("Vertical");
    Vector2 movement = new Vector2(moveHorizontal, moveVertical);
    rb2d.AddForce(movement * speed);


    }

    Anybody spot where it's gone wrong? Managed to get this working for th 3d roller ball game just fine, hmm
     
  33. Tovey-Ansell

    Tovey-Ansell

    Joined:
    Jul 8, 2015
    Posts:
    150
    Managed to get it working, no idea what I did though XD
     
  34. Kevinkestein

    Kevinkestein

    Joined:
    Jul 12, 2016
    Posts:
    1
    Hello,i have problem about controlling the player,actually i checked 3,4 times but there isn't any difference between your code and mine,i can't move my characacter movement keys wont work in my project


    2d ufo player oynatamama.PNG
     
    Last edited: Jul 12, 2016
  35. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Morning,

    One thing to be mindful of, is that C# is case sensitive. The monobehaviours won't have any intellisense when typing.

    Where you have
    fixedUpdate()

    This should be
    FixedUpdate()

    With a capital F. You won't get any errors, it simply won't get called. Change that and see how you get on.
     
    Kevinkestein likes this.
  36. Yaahcacestmoi

    Yaahcacestmoi

    Joined:
    Jul 15, 2016
    Posts:
    2
    Hey guys ! I'm following the tutorial step by step and I encountered a pretty weird problem... I've done everything right up to video 3 of the tutorial, but when I test the "gravity thing", the UFO goes up, and after setting up the commands like shown in the video, the arrow keys are reversed (right arrow make the ufo go left, up arrow goes down, etc...), I saw on a different forum that it could be because of the position of the camera (x:0 , y:0, z:-10). with those settings, I see the background and the ufo "on top", also, they are in the right sorting layer. But if I change the z to (+)10, I just see the grey camera background and nothing else...

    If any of you have a suggestion or even a solution, it would be much appreciated ! :)
    Thanks !
     
  37. Davvv06

    Davvv06

    Joined:
    Jul 16, 2016
    Posts:
    2
    Hi there,

    New to Unity, this is an awesome tuto. Crystal clear instructions, and - cherry on top of the cake - some good practices for coding in C#. Huge thanks !!

    I successfully completed the tuto, but I just encountered a strange situation I'd like to share. It may because of a simple thing I didn't set properly but Iùd like to understand.

    When I tried to set the 'Main Camera' as a child of the 'Player', I couldn't experience the camera-child-of-player game where the screen rotates with the player.
    On my Unity, this forced the camera to be totally superposed with the player, including on the Z axis. It resulted in the camera preview showing the background greyish color and nothing else.

    I then tried to force back the Z position of the camera in its Transform properties, to its initial value of -10. Even more strange: the value was accepted but it didn't change anything. Switching to 3D view, camera was still superposed with the player.



    Any idea ?

    Thanks by advance

    Davvv
     

    Attached Files:

  38. Yaahcacestmoi

    Yaahcacestmoi

    Joined:
    Jul 15, 2016
    Posts:
    2

    Found a solution... pretty simple actually... For those with the same problem, the issue is not the camera position, but it' "size", (I don't really get why), but the camera size can be negative, and that reverse the screen, so just make sure it is a positive number ! :)

    Also thanks to @Davvv06 for that screenshot ! ;)
     
  39. surajsirohi1008

    surajsirohi1008

    Joined:
    Jun 21, 2016
    Posts:
    267
    Hi, I'm experiencing some problems in "collecting the pickups" as the pickups don't disappear when the UFO touches them. Plz help!
     
  40. roumanite

    roumanite

    Joined:
    Jul 23, 2016
    Posts:
    1
    Help im a beginner and i dont know how to download the asset when i click the one i circled red, it says create a project
    how can i download the asset
     

    Attached Files:

    • aaa.png
      aaa.png
      File size:
      240.2 KB
      Views:
      961
    • unity.png
      unity.png
      File size:
      60.5 KB
      Views:
      918
  41. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    you've not really gave us alot to go on to help you out here.

    Are you getting any errors showing in the console.

    can you post your player controller script.
    Have you got the PickUp objects set to the correct tag name?

    Might be worth going through this video again, checking that not only the script is ok, but how the components and gameobjects are set up.
    http://unity3d.com/learn/tutorials/projects/2d-ufo-tutorial/picking-collectables?playlist=25844
     
  42. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    if you create a new 2D project in unity.
    you can go to Window > Asset Store and look for the Unity technologies UFO Tutorial.
    should give you the same download / open option, see how you get on there.
     
  43. daPerley

    daPerley

    Joined:
    Jul 27, 2016
    Posts:
    3
    So next up with a non moving Player with out finding the problem, done the same way as in the Roll-a-Ball MiniGame exept that I've used 2D options this time (ae. Rigidbody 2D).


    I don't get any errors in the program.
     
  44. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Morning,

    You need to remove the tick from 'Is Kinematic' in the Player Rigidbody component.

    With this tick in, you are basically saying that this rigidbody will not be affected by the physics system.

    But, our player in this game IS driven via physics as we are applying external forces to it, and using these physics forces for movement.
     
  45. daPerley

    daPerley

    Joined:
    Jul 27, 2016
    Posts:
    3
    Oh, great, thank you. :)
     
  46. WarriusBirde

    WarriusBirde

    Joined:
    Jul 28, 2016
    Posts:
    4
    I have an issue I figure is more linked to the editor itself than the project.

    I've completed the tutorial and everything works as expected. However, the bottom left portion of the UI canvas that passes through 0,0 is shown in the game. The count and win text portions of the UI function perfectly, but I can't suss out why the canvas border itself is being rendered in the game. I had something similar happen with the background border objects' outlines, but that was due to me having them selected in the editor's hierarchy. Any ideas why this is showing up?
     

    Attached Files:

  47. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    is that in the scene view or the game view window?
     
  48. WarriusBirde

    WarriusBirde

    Joined:
    Jul 28, 2016
    Posts:
    4
    I believe that was the game window, but the shown effect takes place in both scene and game windows. The scene view is to be expected, but why it's carrying over to the game view is a mystery to me.
     
  49. surajsirohi1008

    surajsirohi1008

    Joined:
    Jun 21, 2016
    Posts:
    267
    It was the Tag, thanks!
     
  50. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Just out of curiosity, I clean forgot, do you have Gizmos on in the Game window?
    As there is a toggle button at the top for 'Gizmos', just to the right of 'Maximise on play', 'Mute Audio' etc.

    If you turn Gizmos off (just toggle the button) it should get rid of it, as there is a Gizmo in that list for the Canvas specifically as well.
     
    WarriusBirde likes this.