Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Ruby’s Adventure: 2d Beginner Official Thread

Discussion in 'Community Learning & Teaching' started by katwoolley, Apr 15, 2019.

  1. katwoolley

    katwoolley

    Unity Technologies

    Joined:
    Jan 18, 2018
    Posts:
    3
    2DBeginner_AssetStore_SocialMedia.png

    Alongside our brand new Learn platform, Unity’s Learn Content team have released a new 2D beginner project. This project is a great way to introduce you to beginner code, tilemapper, sprites, collectibles, quest controllers and more, all wrapped up in this RPG style game tutorial.

    Step by step, use the 2D assets provided to help Ruby fix her robot friends. The written lessons have editor screenshots and gifs to help you learn how to re-create the game.
    For the first time we’ve released two versions of our project. You can find the tutorial project where you build the game from scratch, but also the completed project where you can see how we’ve made the demo level and play the game in the editor.


    Find the tutorial on the Unity Learn site here

    Download the Tutorial Project here

    Download the Complete Project here

     
    Last edited: Apr 15, 2019
    GeekyMonkey likes this.
  2. anthonyirwin82

    anthonyirwin82

    Joined:
    Jun 21, 2017
    Posts:
    2
    Hi,

    I am going through this tutorial and really liking it so far.

    I have found a bug in Part 9 Sprite Animation.

    In section 5 Setting animation for the main character you have the following bug in the Update() method:

    Code (CSharp):
    1. // The following is a bug the parameter is actually "Look X" and "Look Y"
    2. animator.SetFloat("Move X", lookDirection.x);
    3. animator.SetFloat("Move Y", lookDirection.y);
    It should actually be the following:

    Code (CSharp):
    1. animator.SetFloat("Look X", lookDirection.x);
    2. animator.SetFloat("Look Y", lookDirection.y);
    Anyway just thought I would point that out as some new users may not be able to easily debug the problem.

    Thanks for the learning tutorials, really great way to get started with Unity.

    Regards,
    Anthony
     
  3. anthonyirwin82

    anthonyirwin82

    Joined:
    Jun 21, 2017
    Posts:
    2
    Found another bug in part 10 World interactions - Projectiles in Section 2 Launching the projectiles

    Code (CSharp):
    1. void Launch()
    2. {
    3.     GameObject projectileObject = Instantiate(projectilePrefab, rigidbody2d.position + Vector2.up * 0.5f, Quaternion.identity);
    4.  
    5.     Projectile projectile = projectileObject.GetComponent<Projectile>();
    6.     projectile.Launch(lookDirection, 300);
    7.  
    8.     // This should be "Launch" also you are not using ascii double quotes so copy and paste has a special “ instead of the asicii " one so visual studio gets upset.
    9.     animator.SetTrigger(“Lauch”);
    10. }
    Regards,
    Anthony
     
  4. MRNXGBRL

    MRNXGBRL

    Joined:
    Apr 13, 2019
    Posts:
    1
    @katwoolley Regarding World Interactions - Collectibles part 1 - character Health. The bottom exercise solution code to 'expose speed' by adding 'public' results in a compiler error? (newb here just starting out)

    Fixed it ! further on down the chapter, don't know how exactly, maybe i just forgot to put in that closing bracket, like the Console kept reminding me a couple of times? I'll probably have to read and go over this chapter a couple of times more over before i truly grasp this beginner C# stuff.tx!
     
    Last edited: May 3, 2019
    katwoolley likes this.
  5. rbagao

    rbagao

    Joined:
    Feb 13, 2016
    Posts:
    18
    Would like to ask if this game has mobile controls or pc only? thanks
     
  6. VGSammich

    VGSammich

    Joined:
    Apr 26, 2019
    Posts:
    1
    Found what may be another issue?
    In chapter 16 Build, Run, Distribute after having completed it and testing the finished build, my player character and enemy characters are moving way too fast. I'm guessing their movement speed is tied to the refresh rate or framerate, but it shouldn't be as Time.deltaTime is incorporated in their scripts and it runs as expected in the Unity Editor.

    This tutorial has been my first time using Unity, so I'm kind of at a roadblock. Any help would be appreciated!

    edit: I have found that running on the default build's ultra-medium settings causes the movements to be too fast, while low-very low cause them to be too slow. I can also replicate this issue in the editor by switching the Quality setting's Vsync to Every Second V Blank. I have also checked to see if my GPU drivers were causing any interference but have determined that it is not. Any help still would be appreciated as this is is something I'd like to resolve in the event I encounter it again in different projects.

    edit2: After no luck, I'm just going to assume it has something to do with unity tying my movement script to some part with my monitor's refresh rate of 144hz. At this time I don't have any other means to determine what may be the cause so if anyone has had or read of any similiar issues please let me know ;P
     
    Last edited: May 16, 2019 at 8:10 PM
  7. AdventurousDrake

    AdventurousDrake

    Joined:
    Mar 18, 2015
    Posts:
    21
    Chapter 12 - 3 Particle System in code.
    Code and tutorial parts missing?

    The tutorial jumps directly to dragging the particle system in to a slot that hasn't been created yet. Even if I create a public variable for for the smoke effect it still doesn't work when I press play in the editor. Maybe I missed something, but after re-reading that section lots of times, I still cannot get it to work. Any help would be greatly appreciated.
     
    keithgobel, CarMarc and madsketchbook like this.
  8. katwoolley

    katwoolley

    Unity Technologies

    Joined:
    Jan 18, 2018
    Posts:
    3
    This project has been created to be used within the Unity editor on Windows or Mac only.
     
  9. TallGuyD

    TallGuyD

    Joined:
    Apr 12, 2019
    Posts:
    3
    Hey, I'm not having any luck with the Ruby Tutorial for beginners. I'm not sure why it's just not working form me. But I have been trying to figure it out for a while and I'm only on the second part. The image I've posted has my script and the errors the console is showing me. Thanks to anyone who can offer a suggestion.
     

    Attached Files:

  10. TallGuyD

    TallGuyD

    Joined:
    Apr 12, 2019
    Posts:
    3
    I have opened unity ver. 2018.3 and repeated the process. It worked correctly, unlike in unity ver. 2019.1.
     
  11. RobotDoc2

    RobotDoc2

    Joined:
    Oct 7, 2018
    Posts:
    2
    2019 breaks a lot of the 2D tutorials. Stick with 2018.3 and you'll save yourself a lot of aggravation.
     
    TallGuyD likes this.
  12. TallGuyD

    TallGuyD

    Joined:
    Apr 12, 2019
    Posts:
    3
    Thank you for the tip.
     
    RobotDoc2 likes this.
  13. RobotDoc2

    RobotDoc2

    Joined:
    Oct 7, 2018
    Posts:
    2
     
    TallGuyD likes this.
  14. darksilence

    darksilence

    Joined:
    Oct 16, 2014
    Posts:
    10
    Its not that, it seems he somehow managed to add duplicate of RubyController.c# to project and when he started clean it solved the problem.
     
  15. darksilence

    darksilence

    Joined:
    Oct 16, 2014
    Posts:
    10
    Was camehere just to write that. But in someway it was good debugging exercise for me, had to write lots of test cases to find what is wrong and eventhough i know how to do it in theory first time i actually put the effort and done that :) So i am glad of the bug for some reason.
     
  16. apo0o0o

    apo0o0o

    Joined:
    Apr 19, 2019
    Posts:
    1
    i'm stuck at that point :-(

    I saw the bug @anthonyirwin82 has shown on the first answer.
    I changed
    animator.SetFloat("Look X", lookDirection.x);
    animator.SetFloat("Look Y", lookDirection.y);

    but I keep on getting error:
    NullReferenceException: Object reference not set to an instance of an object RubyController.Update () (at Assets/Scripts/RubyController.cs:51)

    I commented out the three line:
    //animator.SetFloat("Look X", lookDirection.x);
    //animator.SetFloat("Look Y", lookDirection.y);
    //animator.SetFloat("Speed", move.magnitude);


    and the game can run
    I've also debugged the 3 variable:

    Debug.Log(lookDirection.x + "/" + lookDirection.y);
    Debug.Log(move.magnitude);

    and they works


    so I think the problem is that

    Animator animator;

    is not working, but is written similar to EnemyController

    someone got this problem to?









    This is my code:

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


    public class RubyController : MonoBehaviour
    {
    public float speed = 3.0f;

    public int maxHealth = 5;
    public float timeInvincible = 2.0f;

    public int health { get { return currentHealth; } }

    private int currentHealth;
    bool isInvincible;
    float invincibleTimer;

    Rigidbody2D rigidbody2d;
    Animator animator;



    // Start is called before the first frame update
    void Start()
    {
    rigidbody2d = GetComponent<Rigidbody2D>();

    currentHealth = maxHealth;
    }


    // Update is called once per frame
    void Update()
    {
    float horizontal = Input.GetAxis("Horizontal");
    float vertical = Input.GetAxis("Vertical");

    Vector2 move = new Vector2(horizontal, vertical);

    Vector2 lookDirection = new Vector2(1, 0);

    if (!Mathf.Approximately(move.x, 0.0f) || !Mathf.Approximately(move.y, 0.0f))
    {
    lookDirection.Set(move.x, move.y);
    lookDirection.Normalize();

    }

    //Debug.Log(lookDirection.x + "/" + lookDirection.y);
    //Debug.Log(move.magnitude);
    animator.SetFloat("Look X", lookDirection.x);
    animator.SetFloat("Look Y", lookDirection.y);
    animator.SetFloat("Speed", move.magnitude);

    Vector2 position = rigidbody2d.position;

    position = position + move * speed * Time.deltaTime;

    rigidbody2d.MovePosition(position);

    if (isInvincible)
    {
    invincibleTimer -= Time.deltaTime;
    if (invincibleTimer < 0)
    isInvincible = false;
    }
    }

    public void ChangeHealth(int amount)
    {
    if (amount < 0)
    {
    if (isInvincible)
    return;

    isInvincible = true;
    invincibleTimer = timeInvincible;
    }

    currentHealth = Mathf.Clamp(currentHealth + amount, 0, maxHealth);

    Debug.Log(currentHealth + "/" + maxHealth);
    }
    }




    thanks
     
  17. Natzely

    Natzely

    Joined:
    Sep 9, 2017
    Posts:
    1
    I hope some one can help with this, it's driving me nuts. I'm trying to make my star particle look identical to the example at the top of the Visual Styling - Particles tutorial page, but I can't seem to adjust the particle system to achieve this. Can anyone tell me what the settings are for that? Mine doesn't look anywhere near as smooth.

    Here are my settings:
     
  18. Psyche_

    Psyche_

    Joined:
    May 2, 2018
    Posts:
    10
    Hey,
    I don't see anything wrong with the script at first sight, make sure you are using the right Animator controller in the editor and that you have the same parameters. You get a nullreference exception when those 3 lines are linked and not when you comment them, so I am guessing they can't find the parameters you are wanting to access.
     
  19. Psyche_

    Psyche_

    Joined:
    May 2, 2018
    Posts:
    10
    1. I believe there is a small bug here in CH12PT3 - duplicate image. First one should be fixed if I'm not mistaken.

    duplicateimage.png
     
    Last edited: May 15, 2019
    Tacoor-Gafruf and darksilence like this.
  20. unity_vPTkf-uNWV_3JQ

    unity_vPTkf-uNWV_3JQ

    Joined:
    May 15, 2019
    Posts:
    1
    I actually have the same problem as you have. But I'm also not getting any smarter by looking into the references...
    for the moment i commented those three lines and can play. But Animation is missing tho. ;(
     
  21. Psyche_

    Psyche_

    Joined:
    May 2, 2018
    Posts:
    10
    Can you show your script? Make sure you are working on the Ruby Prefab and that you have assigned Ruby controller in the Animator component.
     
  22. darksilence

    darksilence

    Joined:
    Oct 16, 2014
    Posts:
    10
    Thats correct both animated gifs are same and first one is unnecessary. I finished the tutorial and compiled without any problems 1-2 days ago. But i love the facts that you need to be more and more carefull as you approach towards the end and in sound part they give you one example and let you do the rest (or ignore). Gradually less hand holding. For example in 12-3
    "And to stop the smoke when the robot gets fixed, open the EnemyController script and add a public member of type ParticleSystem called smokeEffect." And nowhere else they show it or the code or how to declare public member of ParticleSystem class. This things are really easy to do by yourself even you didnt know how to do it you acquire the skill along the way. And you can't just rush tutorial mindlessly half awake. Right after completing the project i started my own learning project and i even more appreciate they made the tutorial easy but not mindless. Since there is tens of immediate problems i started face and instead of completely stuck i am progressing (very slowly though)
     
  23. WalkerOfTheSky

    WalkerOfTheSky

    Joined:
    May 9, 2019
    Posts:
    1
    Hi there,

    I have an annoying problem which I don't know how to debug. I hope someone can point me in the right direction.

    I noticed it in chapter 10 when implementing the projectile to fix the robot, but I think I made some mistake during the animation chapter which I can't seem to find

    When I press play to start the game my robot, instead of starting to walk in the right direction, appears a little on top of its starting location leaving its box collider at its original starting location.
    I think it's easier to understand by looking at the screenshots. The first one I took before I press start and the second screenshot is the first frame after pressing start. After that the robot walks perfectly but the box collider, while moving with the robot, always stays underneath the robot. So basically to repair it I have to shoot below the robot instead of right at it.


    01.png

    02_firstFrameAfterPlay.png


    I'm using Unity Version 2019.1.2f1

    Thanks in advance.
     

    Attached Files:

  24. GeekyMonkey

    GeekyMonkey

    Joined:
    Feb 9, 2013
    Posts:
    12
    You need to initialize your "animator" variable in the Start() function, just as you do for the "rigidbody2d" variable.
     
  25. GeekyMonkey

    GeekyMonkey

    Joined:
    Feb 9, 2013
    Posts:
    12
    I think your problem is actually in the pivot points of your sprites. Look at each frame of the robot spritesheet and make sure all of them have the pivot at bottom center. Then adjust your box collider position.
     
  26. benfarrantsmith

    benfarrantsmith

    Joined:
    May 15, 2019
    Posts:
    4

    I need help with the beginning of step 2, in part 10.

    Let’s start by creating a public variable in our RubyController script that we will call projectilePrefab. We’ll make it a GameObject type because that’s what prefabs are; GameObjects saved as assets. Because we’ve made it public, it appears in our Editor as a slot where we can assign any GameObject.

    ^^This Bit^^

    How do I do it?

    Thanks.
     
  27. darksilence

    darksilence

    Joined:
    Oct 16, 2014
    Posts:
    10
    public GameObject projectilePrefab;

    You should consider starting from beginning of the tutorial since it seems you missed even most basic things.
     
  28. mr_noodler

    mr_noodler

    Joined:
    May 11, 2019
    Posts:
    2
    Hello,

    I'm having a problem with the Damage received from enemies, particularly the line void OnCollisionEnter2D(Collision2D other) is not being called during gameplay. Any ideas as to why this is happening?

    I have followed the tutorial in setting up the character as a sprite with a Rigidbody 2D and a Box Collider 2D.and I am using Unity 2019.1.2f1 Personal.

    Is there something that I am missing? Please see my source below:

    //////////////////Code/////////////////

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

    public class EnemyController : MonoBehaviour
    {
    public float speed = 3.0f;
    public bool vertical;
    public float changeTime = 3.0f;

    Rigidbody2D rigidbody2D;
    float timer;
    int direction = 1;

    // Start is called before the first frame update
    void Start()
    {
    rigidbody2D = GetComponent<Rigidbody2D>();
    timer = changeTime;
    }

    // Update is called once per frame
    void Update()
    {

    timer -= Time.deltaTime;

    if (timer < 0)
    {
    direction = -direction;
    timer = changeTime;
    }


    Vector2 position = rigidbody2D.position;

    if (vertical)
    {
    position.y = position.y + Time.deltaTime * speed * direction;
    }
    else
    {
    position.x = position.x + Time.deltaTime * speed * direction;
    }

    rigidbody2D.MovePosition(position);

    void OnCollisionEnter2D(Collision2D other)
    {
    Debug.Log("first");

    RubyController player = other.gameObject.GetComponent<RubyController>();
    Debug.Log("got here");

    if (player != null)
    {
    player.ChangeHealth(-1);
    }
    }
    }
    }
     
  29. mr_noodler

    mr_noodler

    Joined:
    May 11, 2019
    Posts:
    2
    I completely figured out my own problem!! I put the 'void OnCollisionEnter2D(Collision2D other) into the 'void Update' method. So to fix my problem I put it outside the void Update method and everything works fine now.
     
  30. SynolBAKA

    SynolBAKA

    Joined:
    Monday
    Posts:
    1
    Found a few bugs in 9. Sprite Animation. Seems a few others are finding them also so I'll post the solutions here.

    First, the collision box on the animations is well below where it is on the actual Robot object. Not sure if it is because I resized the Robot, but someone above posted the same issue.

    The fix is to open the Robot prefab and then to open the Animation screen (ctrl+6). Click the Play button to get the animation running and then in the inspector you can move the collision box to the right spot. There seems to be an independent collision box for animations and objects, a pretty strange way to do it.


    Second, when you go into detail on which code to enter into RubyController you skip the part that should go into the Start function.

    The fix is to add animator = gameObject.GetComponent<Animator>(); into the Start() function just the way you did with the EnemyController script in the first part.



    Hope this helps some other people.
     
  31. benfarrantsmith

    benfarrantsmith

    Joined:
    May 15, 2019
    Posts:
    4
    Thanks, I am a casual, don't worry.
     
  32. changlihan4595

    changlihan4595

    Joined:
    Sunday
    Posts:
    1
    In 12th tutorial visual styling- particle step 4. How could I make get hit effect and health collection effect working properly? I created prefabs for both get hit effect and health collection effect, and also did the same stuff as I did for smoke effect on robots and also folliowing
    • Disable Looping and set the Stop Action to Destroy.

    • Set the Rate over Time to 0, to not generate any particles over time.

    • Set a burst of 20 particles at time 0.0
    and use Instantiate(hitEffect) and Instantiate(healthCollectionEffect) in RubyController script.

    I uploaded the script, could somebody tell me how to make hitEffect correctly triggered.
     

    Attached Files:

  33. manas16

    manas16

    Joined:
    May 4, 2019
    Posts:
    1
    Thank You so much , Second point helped me