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

Official Ruby’s Adventure: 2d Beginner Official Thread

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

  1. Barabulkaa

    Barabulkaa

    Joined:
    Nov 2, 2021
    Posts:
    4
    I have solved the issues above - Robot Box Collider had is trigger on which why it was not working.
    I had the similar issue with animation of the smoking effect and aligning to Z solved it as well as making sure that child of the robot prefab - smoke effect is pasted into the smoke effect tab in Inspector. That solved smoke effect dissapearing on the camera and sometimes appearing and dissapearing and also when robot fixed - smoke effect dissapears.
     
  2. ngrash

    ngrash

    Joined:
    Jan 10, 2022
    Posts:
    4
    I recently created another thread with a problem I had while following this tutorial and was told this mega thread exists. I already found a solution and posted it in my original thread but thought it might be helpful to post a backlink here in case anyone is searching this thread for a solution to the same problem I had.

    Ruby's Adventure: Ruby constantly pushed after collision with enemy robot
     
  3. SpacePotato18

    SpacePotato18

    Joined:
    Jan 9, 2022
    Posts:
    1
    Been following the tutorial and everything working up until Sprite Animation 9.Sending parameters to the Animator Controller. I'm also encountering the issue with the animation only showing the walking right. Admittedly I did resize the Robot and figured I'd have the same issue as above, though when I follow those steps to to fix


    my problem is when I have the animation screen open and playing it says move the collision box to the right spot... How is that done or have changes in the product made this fix a bit different in 2022?


    EDIT - Wow, it took me a while to notice my parameters Move X and Move Y were referenced as MoveX and Y with no space in Unity animator, but in the controller script they had spaces. Ouch.
     
    Last edited: Feb 14, 2022
  4. No_More_Pasta

    No_More_Pasta

    Joined:
    Jun 17, 2021
    Posts:
    2
    I'm having a ridiculously small but annoying issue. I'm at the Health Collectible section of the tutorial and I'm doing the part where I modify the HealthCollectible script attached to the strawberry. I'm at section 10 where I delete the log and input the provided code to give Ruby Health. I do so and I get a compiling error: (16,6): error CS1513: } expected

    I have no idea where I'm suppose to put the "}" at. Here's how the code in the script looks.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class HealthCollectible : MonoBehaviour
    6. {
    7.     void OnTriggerEnter2D(Collider2D other)
    8.     {
    9.         RubyController controller = other.GetComponent<RubyController>();
    10.  
    11.         if (controller != null)
    12.         {
    13.             controller.ChangeHealth(1);
    14.             Destroy(gameObject);
    15.         }
    16.     }
    I tried moving that last bracket around and I'm still getting a syntax error.

    EDIT: Solved. It was part of the tutorial for there to be an error and didn't realize. I wish it was noted in the current or next step instead of being mentioned two steps down.
     
    Last edited: Mar 2, 2022
  5. JV65

    JV65

    Joined:
    Feb 8, 2022
    Posts:
    1
    I had the same trouble. Your mistake is probably on this line in the Update method in the RubyController script:

    Code (CSharp):
    1. if (!Mathf.Approximately(move.x, 0.0f) || !Mathf.Approximately(move.y, 0.0f))
    That happened, because when move.x (or move.y) is aproximately to 0 should be the idle first ruby's pose (or the last that you presed). However, it isn't, Ruby looks to the direction that have look direction in the first time every time, when it's not moving. In any case, I forgot "!" int he start of Math, maybe you too. It also fixes the bug with the cogs, because the problem is in the box collider when Ruby looks in the wrong direction.

    I hope you fix it ;).
     
  6. muelroboso

    muelroboso

    Joined:
    Mar 10, 2017
    Posts:
    1
    Dude I don't know if this is anymore useful to you but I will put it here anyway for reference (also because I know I am going to forget about it and I will search for it again).
    The
    inspector
    they are referring to here is not the script inspector. They refer to the script inspector within the Jambi GameObject.
    So to correctly assign the DialogBox GameObject (the child of Jambi in the hierarchy) to the script you have to check the inspector of Jambi, and move the script in the
    dialogBox
    slot.
    There might be a way to do it for the prefab but I didn't try yet.
     
  7. yearlyweekly

    yearlyweekly

    Joined:
    Nov 10, 2021
    Posts:
    1
    Hey anyone reading this,

    I'm having an issue here on World Interactions-Collectibles when adding a ChangeHealth function:

    Here's the code I've entered based on what the tutorial showed:
    Code (CSharp):
    1. Public class RubyController2 : MonoBehaviour
    2.  
    3. {
    4.  
    5.     public int maxHealth = 5;
    6.     int currentHealth;
    7.  
    8.     Rigidbody2D rigidbody2d;
    9.     float horizontal;
    10.     float vertical;
    11.  
    12.     // Start is called before the first frame update
    13.     void Start()
    14.     {
    15.         rigidbody2d = GetComponent<Rigidbody2D>();
    16.  
    17.         currentHealth = maxHealth;
    18.     }
    19.  
    20.     // Update is called once per frame
    21.     void Update()
    22.     {
    23.         horizontal = Input.GetAxis ("Horizontal");
    24.         vertical = Input.GetAxis("Vertical");
    25.  
    26.     }
    27.     void FixedUpdate()
    28.     {
    29.         Vector2 position = rigidbody2d.position;
    30.         position.x = position.x 3.0f * horizontal * Time.deltaTime;
    31.         position.y = position.y + 3.0f * vertical * Time.deltaTime;
    32.  
    33.         rigidbody2d.MovePosition(position);
    34.     }
    35.  
    36.     void ChangeHealth(int amount)
    37.     {
    38.         currentHealth = Mathf.Clamp(currentHealth + amount, 0, maxHealth);
    39.         Debug.Log(currentHealth + "/" + maxHealth);
    40.     }
    41. }

    For some reason, this code doesn't add a property to the script component. What have I done wrong? I keep getting this:
    Assets/Scripts/NewController.cs(31,33): error CS1002: ; expected

    Edit: Just learned how to read the errors

    Edit 2: NVM I just had some typos lol
     
    Last edited: May 5, 2022
  8. Rundus

    Rundus

    Joined:
    Jan 11, 2022
    Posts:
    2
    Hello,

    I've recently been working through the Audio tutorial for Ruby and encountered an error I do not fully comprehend.

    As I understand it, it has to do with the "PlayOneShot" method not being able to find the audioClip I'm using, thus resulting in an error: "ArguementNullException: Value cannot be Null. Parameter name: source". I'm following the tutorial guide, so my code should match the tutorial's "check your script" exactly. Despite this I still get the error.

    I have confirmed the following:
    (1) The audio .wav files are in the audio folder in the project menu (2) The public variables defined in the relevant scripts (RubyController and HealthCollectable) have the correct audio files dragged and dropped into them via the inspector and (3) I've updated my unity to 2020.3.



    Here's the code I'm using, the issue (I believe) is the final lines of PlaySound() method:



    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class RubyController : MonoBehaviour
    6. {
    7.     public float speed = 3.0f;
    8.  
    9.     public int maxHealth = 5;
    10.  
    11.     public GameObject projectilePrefab;
    12.  
    13.     public AudioClip throwSound;
    14.     public AudioClip hitSound;
    15.  
    16.     public int health { get { return currentHealth; }}
    17.     int currentHealth;
    18.  
    19.     public float timeInvincible = 2.0f;
    20.     bool isInvincible;
    21.     float invincibleTimer;
    22.  
    23.     Rigidbody2D rigidbody2d;
    24.     float horizontal;
    25.     float vertical;
    26.  
    27.     Animator animator;
    28.     Vector2 lookDirection = new Vector2(1,0);
    29.  
    30.     AudioSource audioSource;
    31.  
    32.     // Start is called before the first frame update
    33.     void Start()
    34.     {
    35.         rigidbody2d = GetComponent<Rigidbody2D>();
    36.         animator = GetComponent<Animator>();
    37.  
    38.         currentHealth = maxHealth;
    39.  
    40.         audioSource = GetComponent<AudioSource>();
    41.     }
    42.  
    43.     // Update is called once per frame
    44.     void Update()
    45.     {
    46.         horizontal = Input.GetAxis("Horizontal");
    47.         vertical = Input.GetAxis("Vertical");
    48.  
    49.         Vector2 move = new Vector2(horizontal, vertical);
    50.  
    51.         if(!Mathf.Approximately(move.x, 0.0f) || !Mathf.Approximately(move.y, 0.0f))
    52.         {
    53.             lookDirection.Set(move.x, move.y);
    54.             lookDirection.Normalize();
    55.         }
    56.  
    57.         animator.SetFloat("Look X", lookDirection.x);
    58.         animator.SetFloat("Look Y", lookDirection.y);
    59.         animator.SetFloat("Speed", move.magnitude);
    60.  
    61.         if (isInvincible)
    62.         {
    63.             invincibleTimer -= Time.deltaTime;
    64.             if (invincibleTimer < 0)
    65.                 isInvincible = false;
    66.         }
    67.  
    68.         if(Input.GetKeyDown(KeyCode.C))
    69.         {
    70.             Launch();
    71.         }
    72.  
    73.         if (Input.GetKeyDown(KeyCode.X))
    74.         {
    75.             RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC"));
    76.             if (hit.collider != null)
    77.             {
    78.                 NonPlayerCharacter character = hit.collider.GetComponent<NonPlayerCharacter>();
    79.                 if (character != null)
    80.                 {
    81.                     character.DisplayDialog();
    82.                 }
    83.             }
    84.         }
    85.     }
    86.  
    87.     void FixedUpdate()
    88.     {
    89.         Vector2 position = rigidbody2d.position;
    90.         position.x = position.x + speed * horizontal * Time.deltaTime;
    91.         position.y = position.y + speed * vertical * Time.deltaTime;
    92.  
    93.         rigidbody2d.MovePosition(position);
    94.     }
    95.  
    96.     public void ChangeHealth(int amount)
    97.     {
    98.         if (amount < 0)
    99.         {
    100.             if (isInvincible)
    101.                 return;
    102.  
    103.             isInvincible = true;
    104.             invincibleTimer = timeInvincible;
    105.  
    106.             PlaySound(hitSound);
    107.         }
    108.  
    109.         currentHealth = Mathf.Clamp(currentHealth + amount, 0, maxHealth);
    110.  
    111.         UIHealthBar.instance.SetValue(currentHealth / (float)maxHealth);
    112.     }
    113.  
    114.     void Launch()
    115.     {
    116.         GameObject projectileObject = Instantiate(projectilePrefab, rigidbody2d.position + Vector2.up * 0.5f, Quaternion.identity);
    117.  
    118.         Projectile projectile = projectileObject.GetComponent<Projectile>();
    119.         projectile.Launch(lookDirection, 300);
    120.  
    121.         animator.SetTrigger("Launch");
    122.  
    123.         PlaySound(throwSound);
    124.     }
    125.  
    126.     public void PlaySound(AudioClip clip)
    127.     {
    128.         audioSource.PlayOneShot(clip);
    129.     }
    130. } // END PUBLIC CLASS
    131.  

    I'd be grateful if anyone can work with me to elucidate what the issue is.
     
  9. Rundus

    Rundus

    Joined:
    Jan 11, 2022
    Posts:
    2

    EDIT: I finally figured it out. The tutorial doesn't explicitly say to add an Audio Source component to the Prefab for each new sound, but this worked. The tutorial showed me how to do this before but the steps that tell you to add the new sounds didn't make it clear (to me) that you have to add a new component in the inspector.
     
    safew likes this.
  10. Neossir

    Neossir

    Joined:
    Jun 3, 2022
    Posts:
    1
    Same problem! When I move the character, it's jittering. Exactly the same way it did when hitting the box in the "World Interactions - Blocking Movement" chapter. I really don't know where that comes from. I've tried to copy/paste all the scripts from the tutorial, it doesn't change a thing.

    Did anyone find how to deal with this problem? Thanks!
     
  11. pixxeidust

    pixxeidust

    Joined:
    Oct 14, 2022
    Posts:
    1
    I'm having a bit of trouble with World Interactions - Collectibles (and the following section on Damage Zones). I'm super sorry because I know this thread is pretty old but I'm really struggling!

    With the use of Properties to be able to access the currentHealth variable, which is private, it still doesn't work. I originally resorted to just making it public, but for some reason my sprite isn't registering its collisions with my damage zone sprite or my health collectible and I can't tell whether the two things are related or not. I've looked through all my code and the Unity editor doesn't come up with any errors, and I've made sure it's debug logging all the steps so that I know whether it's registering the collision at all and it doesn't come up with anything. The sprites seem to just not register that the player is entering them at all.

    A classmate told me I need to add Rigidbody 2D components to them, and I did so, but it hasn't changed it at all. I need this for my IT assessment and I just don't know what to do, please help!
     
  12. ACates93

    ACates93

    Joined:
    Feb 4, 2023
    Posts:
    1
    I am struggling on the animator section.. My ruby doesn't have any of the parameters for the animator and I am stuck on what to do
     
  13. NotTodayDio

    NotTodayDio

    Joined:
    Jul 2, 2023
    Posts:
    1
    Hi, I was wondering if anyone knows when this will be updated? The tutorial says that it will be updated in 2023. I want to begin the tutorial but wondering if I should hold off on the updated version if it's planned to be released soon.
     
  14. SupEN0VAPri

    SupEN0VAPri

    Joined:
    Mar 7, 2021
    Posts:
    1
    GREAT help my friend ! thx
     
  15. halfawake01

    halfawake01

    Joined:
    Jul 19, 2023
    Posts:
    4
    To fix the full-screen bug, try using Unity's Rigidbody component for movement instead of directly modifying the position. Add Rigidbody components to Ruby and the robots, and in your movement script, replace position = position + move * speed * Time.deltaTime; with rigidbody.velocity = move * speed;. This should make their movement frame-rate independent and work fine in full-screen mode
     
  16. unity_47C1CF46449BF99811F0

    unity_47C1CF46449BF99811F0

    Joined:
    Dec 1, 2023
    Posts:
    1
    Hey, I have been having some trouble with part 13, section 13. When I try to play the game Ruby doesn't take damage. I don't know how to fix this, but there is an error message which is most likely the solution. . I am using the solutions code, with no deviations.
     

    Attached Files:

  17. kmamor

    kmamor

    Joined:
    Sep 22, 2023
    Posts:
    1
    I'm on the Sprite Animation tutorial and have set up the Robot animation controller and assigned it to the Robot prefab. I immediately get the error message " [Worker0] The animator controller you have used is not valid. Animations will not play." The next step in the tutorial is to open the animation window and press create - but that option does not appear. Would appreciate any help!
     
  18. Devilzelite46

    Devilzelite46

    Joined:
    Feb 15, 2024
    Posts:
    1
    I'm not sure if I have found a bug. But after completing the Partical System. And adding smoke to the robot. I get a Null reference Exception error. UnityEditor.Graphs.Edge.Wakeup () (at <e57e06bbfb424c1c9ddaf1d45eb1f785>:0)
    I'm Using 2021.3 I believe and not really had much trouble up until now.
     
  19. LDenn

    LDenn

    Joined:
    Jan 30, 2024
    Posts:
    1
    Thank you!