Speed and Parallax BG | MAKE AN INFINITE RUNNER game like CANABALT #2 | Unity How to Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 13 ธ.ค. 2024

ความคิดเห็น • 86

  • @superjustin5000
    @superjustin5000  3 ปีที่แล้ว +13

    As pointed out by
    @SHWANtheMAN , there is a cut at 11:58 where and it's not shown but I set the 'depth' variable to public in the Parallax script causing it to appear in the Inspector suddenly.

    • @danielmarquez5532
      @danielmarquez5532 2 ปีที่แล้ว +1

      hi i cant figure it out to let it show the depth option can you help me?

    • @superjustin5000
      @superjustin5000  2 ปีที่แล้ว +1

      @@danielmarquez5532 Ahh OK, it should only take a modification to the Parallax script and making the depth variable public, which only requires that the word 'public' be in front of the variable, so instead of 'float depth;' make it 'public float depth;'

    • @danielmarquez5532
      @danielmarquez5532 2 ปีที่แล้ว

      @@superjustin5000 thnx alot💪

  • @MrSeether75
    @MrSeether75 6 หลายเดือนก่อน +4

    5:26 - It took me a long time to work this out, but if you use Text Mesh Pro for this, you will get a "NullReferenceException: Object reference not set to an instance of an object
    UIController.Update () (at Assets/Scripts/UIController.cs:26)error" when you test the game. However if you use, UI - Legacy - Text it will work as per the video. Hope that helps and saves someone else some time 😁

    • @superjustin5000
      @superjustin5000  6 หลายเดือนก่อน +1

      Yes I've seen a lot of comments about Null Reference exceptions for this video, and that is a highly likely reason. Thank you!

    • @astrifarhansatriorahadian536
      @astrifarhansatriorahadian536 5 หลายเดือนก่อน +1

      Oooooh, I was trying to fix this for a while. Massive thanks!

    • @scKob
      @scKob 3 หลายเดือนก่อน +1

      I was trying to fix this for SOOO long and had no idea why, BIG MASSIVE THANKS TO YOU!

  • @nicovutrik-zn7pm
    @nicovutrik-zn7pm 10 หลายเดือนก่อน

    My man, you literally added in the OG Ninja Gaiden NES game for the parallax examples...LOVE THIS

  • @Herytik
    @Herytik 2 ปีที่แล้ว +1

    remember if you run into errors, always check the placements of your curly brackets. I was running into a lot until i changed the placements and it started to work as shown. a big help for me to remember this stuff is comment your code on what youre trying to do with these blocks of code

  • @Virtualangello
    @Virtualangello 3 ปีที่แล้ว +3

    Awesome video series. You deserve more views and subscribers. Keep up the good work

    • @superjustin5000
      @superjustin5000  3 ปีที่แล้ว +1

      Yo thanks for the encouragement, it means a ton!

  • @XanderwoodGameDev
    @XanderwoodGameDev 3 ปีที่แล้ว +3

    Nice video my man, I am a massive fan of parallax BGs, they just add so much to the look and feel.

    • @superjustin5000
      @superjustin5000  3 ปีที่แล้ว +1

      Absolutely! And relatively simple to implement in most cases.

  • @Jose-vv9ho
    @Jose-vv9ho 3 ปีที่แล้ว +1

    So nice! I hope you keep uploading :)

    • @superjustin5000
      @superjustin5000  3 ปีที่แล้ว +2

      Hey, thanks Jose, that means a lot. Touching up part 3 as we speak, should be up tomorrow actually.

  • @shwantheman1173
    @shwantheman1173 3 ปีที่แล้ว +2

    how did you get the paralax script to have a Depth modifier? at 11:57 the script does not have a Depth Modifier and then at 11:59 it does, there is a small cut during 11:58 , what did you do?

    • @shwantheman1173
      @shwantheman1173 3 ปีที่แล้ว +2

      ah I figured it out! you added Public before the depth float during the cut! few glad I figured that out. these videos have been very helpful thank you!

    • @superjustin5000
      @superjustin5000  3 ปีที่แล้ว +3

      @@shwantheman1173 Ah yea, I cut this video in a rush. Thanks for the catch, I'll be more careful in the future. And thanks a lot, glad you're liking it!

  • @RockDude65
    @RockDude65 3 ปีที่แล้ว +3

    My background isnt moving at all. I don't know why - below is my Parallax script
    // Script starts here
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class Parallax : MonoBehaviour
    {
    public float depth = 1;
    Player player;
    private void Awake()
    {
    player = GameObject.Find("Player").GetComponent();
    }
    // Start is called before the first frame update
    void Start()
    {
    }
    // Update is called once per frame
    void FixedUpdate()
    {
    float realVelocity = player.velocity.x / depth;
    Vector2 pos = transform.position;
    pos.x -= realVelocity * Time.fixedDeltaTime;
    if (pos.x

    • @superjustin5000
      @superjustin5000  3 ปีที่แล้ว

      What's up with

    • @RockDude65
      @RockDude65 3 ปีที่แล้ว

      @@superjustin5000 I've managed to fix it. I downloaded the project files, and then just copy and pasted the code I needed. That seemed to work

    • @superjustin5000
      @superjustin5000  3 ปีที่แล้ว

      @@RockDude65 awesome! 🤘

    • @yunan9760
      @yunan9760 3 ปีที่แล้ว

      @@RockDude65 how did u do that? i only get null reference

    • @superjustin5000
      @superjustin5000  3 ปีที่แล้ว

      @Simple Still experiencing issues?

  • @stebelisimisimo295
    @stebelisimisimo295 3 ปีที่แล้ว +3

    Hello, I have a problem with a part of the script for displaying the distance of the run.
    When I try to write "Player player;" and "Text distanceText;" I get one error for each one which says:
    1. "error CS0246: The type or namespace name 'Player' could not be found (are you missing a using directive or an assembly reference?)"
    2. "error CS0246: The type or namespace name 'Text' could not be found (are you missing a using directive or an assembly reference?)
    How can I solve it?

    • @superjustin5000
      @superjustin5000  3 ปีที่แล้ว

      Would say double check the script/class names of the player script. And for Text at the top of your file, you'll have to add, using UnityEngine.UI

  • @revion592
    @revion592 3 ปีที่แล้ว +1

    I started remaking the script so i can add comments for understanding to it, but then I got a problem on minute 8:24 with the line 27 where it says:
    int distance = Mathf.FloorToInt(player.distance);
    and the error I get is: NullReferenceException: Object reference not set to an instance of an object
    UIController.Update () (at Assets/Scripts/UIController.cs:26)
    And I can't figure out why, because I wrote exactly the same things which you wrote and added the script to the Canvas like you did...

    • @superjustin5000
      @superjustin5000  3 ปีที่แล้ว +1

      player should have a value from line 14 - GameObject.Find("Player").
      I imagine either your game object is not named 'Player' or it doesn't have the Player script attached. Could that be it?

    • @revion592
      @revion592 3 ปีที่แล้ว +1

      @@superjustin5000 Just checked and yes it was! Thank you! :)

    • @Unctrainingacademy
      @Unctrainingacademy ปีที่แล้ว +1

      @@superjustin5000 I'm having this same issue however my script is named Player and so is my Hierachy component, it for some reason isn't working. can't quite figure out why

  • @ihsantelli8991
    @ihsantelli8991 ปีที่แล้ว

    "Hello, I have a question. I have set up the speed section as you did, but I encountered a problem where the character's speed increases only when I press the space bar, which is the jump button. How can I fix this issue?"

  • @devendran.-.9263
    @devendran.-.9263 2 ปีที่แล้ว +2

    hey just wanted to ask. what if I wanted a endless loop background? like 1 image just loops endlessly without disappearing?

    • @superjustin5000
      @superjustin5000  2 ปีที่แล้ว +1

      You would achieve this effect by having two identical images next to each other, that flip from front to back at the right time.
      I do this in one of the recent livestream archives I posted here : th-cam.com/video/kDVDSgcKD4w/w-d-xo.html
      Hope that helps.

    • @devendran.-.9263
      @devendran.-.9263 2 ปีที่แล้ว +1

      @@superjustin5000 alright ill check it out. thanks! this helps me out a lot since im creating a game for my final year project

  • @marmikemp3767
    @marmikemp3767 2 ปีที่แล้ว

    Nice tutorial 👍

  • @LemonTheWise347
    @LemonTheWise347 3 ปีที่แล้ว +1

    First time ever using UI.

  • @lipee1663
    @lipee1663 2 ปีที่แล้ว +1

    Awsome tutorial! I have a question about the X velocity, can I use it to speed up the game someway, even with the x value of the player never actually changing?

    • @superjustin5000
      @superjustin5000  2 ปีที่แล้ว

      Yep, exactly what's happening. Everything else will essentially be moving faster based on that value.

  • @coolerbones
    @coolerbones 2 ปีที่แล้ว +1

    i've got a quick question. what if instead of random objects in the background, i want there to be something constantly on screen, like grass or hills?

    • @superjustin5000
      @superjustin5000  2 ปีที่แล้ว +1

      If it doesn't move, then you can just drag an image from assets into the hierarchy and set it's sort order to something very small

    • @coolerbones
      @coolerbones 2 ปีที่แล้ว

      @@superjustin5000 what if it does move?

    • @superjustin5000
      @superjustin5000  2 ปีที่แล้ว +1

      Hmm, I see what you mean. You want something that repeats itself endlessly. This can get tricky depending on what you want out of it. But you can set up two backgrounds that are the same image at the same z position. You'd have to change at exactly which x position triggers them to jump back from the left side to the right side, but this would repeat it forever.

    • @coolerbones
      @coolerbones 2 ปีที่แล้ว +1

      @@superjustin5000 thanks a million dude

    • @superjustin5000
      @superjustin5000  2 ปีที่แล้ว +2

      Got inspired by your question to upload a full series of videos I've had archived, building a full game. In this video I go through the process of creating background like the one you were describing:
      th-cam.com/video/kDVDSgcKD4w/w-d-xo.html

  • @StoicFlame
    @StoicFlame 2 ปีที่แล้ว +1

    i wish you set the default value for the variable isGrounded at True instead of False so it's less confusing.

    • @superjustin5000
      @superjustin5000  2 ปีที่แล้ว

      I did that so that the player would start off falling down, then land on the ground for the first time naturally. But I can see where that seems unnatural.

  • @romus007
    @romus007 ปีที่แล้ว +1

    Hey, even though it's already 2 years old vid your guide is very helpful. Unfortunately while making a text with distance player has run, I keep getting the same error while running the game. NullReferenceException: Object reference not set to an instance of an object
    UIController.Update () (at Assets/UIController.cs:24). No matter what I did I wasn't able to fix this issue. It says I have something wrong in 24 code line {distanceText.text= "Score" + distance;} and I dont think that this line of code isnt the issue and made sure that player and distanceText arent equal null.

    • @superjustin5000
      @superjustin5000  ปีที่แล้ว

      How and where are you assigning a value to distanceText? (Unless you're not stuck here anymore, sorry for the delayed response)

  • @levis6634
    @levis6634 3 ปีที่แล้ว +1

    I have problem: "Object reference not set to an instance of an object
    UIController.Update ()" how can I fix it?

    • @levis6634
      @levis6634 3 ปีที่แล้ว +1

      i restarted unity and it started working lol

    • @superjustin5000
      @superjustin5000  3 ปีที่แล้ว +1

      Haha, maybe something in the scene got unlinked accidentally. Unity IS known for its "seemingly" random issues.

    • @levis6634
      @levis6634 3 ปีที่แล้ว

      @@superjustin5000 yeah i’m new to unity and i can say for sure that your tutorials are the best. keep it up

    • @superjustin5000
      @superjustin5000  3 ปีที่แล้ว

      That comment goes a long way, so thanks a lot for saying that.

  • @supergamer5573
    @supergamer5573 2 ปีที่แล้ว +1

    What namespace is the Player type from? it says it doesnt recognize the name space and i cant get it to work. Thanks in advance!

    • @superjustin5000
      @superjustin5000  2 ปีที่แล้ว

      Hi, that error is strange. The Player type is a custom class created by us, and isn't part of a special namespace so I'm not sure what unity is trying to tell you is wrong. Did you also name the script, 'Player'?

    • @supergamer5573
      @supergamer5573 2 ปีที่แล้ว

      @@superjustin5000 I named the script UIController

    • @superjustin5000
      @superjustin5000  2 ปีที่แล้ว

      @@supergamer5573 oh no I meant the script where the player code is, from the first video. Because that's what you're trying to reference

    • @supergamer5573
      @supergamer5573 2 ปีที่แล้ว +1

      @@superjustin5000 ahhh thank you so much haha brainfart, I named it Infinite runner

    • @superjustin5000
      @superjustin5000  2 ปีที่แล้ว

      @@supergamer5573 awesome

  • @suguboii7688
    @suguboii7688 ปีที่แล้ว

    Idk why but the depth float doesn’t appear in the inspector. I’ve got no complier errors or anything.

    • @superjustin5000
      @superjustin5000  ปีที่แล้ว

      put a 'public' label in front of the variable name, i think there's a skip in the video edit where I leave out that part

  • @xpelillo1148
    @xpelillo1148 2 ปีที่แล้ว

    hiiiii thk for this collection of videos!!!
    Till now i didn't got an error but now it gives me this :
    NullReferenceException: Object reference not set to an instance of an object
    UIController.Update () (at Assets/Scripts/UIController.cs:28)
    and i'm pretty sure i did exatly what you do , had the same error on another game like chrome dino game , always when i have to set the score , it maybe be caus when i had to create from ud , "Text" the only option i have is Text-TextMeshPro.
    what can i do ???

    • @superjustin5000
      @superjustin5000  2 ปีที่แล้ว +1

      Good point not sure if text mesh pro component is accessible when specifying Text in the getcomponent call. Can you change the type in the script to text mesh pro?

    • @jaimyvankralingen3040
      @jaimyvankralingen3040 2 ปีที่แล้ว +5

      Just figured out you have to add
      using TMPro;
      You can then change the Text to TextMeshProUGUI. Hope this works for you :)

  • @kodev.mp4
    @kodev.mp4 2 ปีที่แล้ว

    hey i have a problem
    the counter only progress when im jumping how do i fix it ?

    • @superjustin5000
      @superjustin5000  2 ปีที่แล้ว

      the distance must only be incrementing inside one of the "if (!grounded)" sections.

    • @kodev.mp4
      @kodev.mp4 2 ปีที่แล้ว

      @@superjustin5000 oh thanks istg u are the best i love u so much ❤️

  • @BlackIce420
    @BlackIce420 2 ปีที่แล้ว +1

    i swear everything is the same here and for some reason my player is moving really fast at the start

    • @superjustin5000
      @superjustin5000  2 ปีที่แล้ว

      Yea I've seen that, probably something with the initial values of the player variables. Double check the player attributes in the inspector?

    • @BlackIce420
      @BlackIce420 2 ปีที่แล้ว

      @@superjustin5000 well i lowered max acceleration and acceleration and that slowed it down pretty good in the inspector and it seems to have slowed down to a decent pace im about to start the next video , thanks for the tutorial by the way :)

    • @coolerbones
      @coolerbones 2 ปีที่แล้ว

      @@BlackIce420 another thing to try is max x velocity. it was really fast and i lowered that and it seemed to work nice. but that's more so if you also want the player to just move slower in general

  • @InfiniteVisions612
    @InfiniteVisions612 2 ปีที่แล้ว

    so at the scoring script i get this error : NullReferenceException: Object reference not set to an instance of an object
    UIController.Update ()
    heres my script:
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;
    public class UIController : MonoBehaviour
    {
    Player player;
    Text distanceText;
    private void Awake()
    {
    player = GameObject.Find("Player").GetComponent();
    distanceText = GameObject.Find("DistanceText").GetComponent();
    }
    // Update is called once per frame
    void Update()
    {
    int distance = Mathf.FloorToInt(player.distance);
    distanceText.text = distance + " m";
    }
    }

  • @marc5163
    @marc5163 2 ปีที่แล้ว +1

    (15:00)

  • @J0hnLedez
    @J0hnLedez 10 หลายเดือนก่อน

    Hello, i am getting the error
    Null referenceException: Object reference not set to an instance of an object UIController.Update() (at Assets/Scripts/UiController.cs:27)
    My UIController script is attached to the Canvas Game object
    My Player script is attached to my Player game object.
    The Game Object for the player is name "Player"
    The Player script is name "Player" it has the class name "Player"

    The UIController script is named "UIController" it is attached to the Canvas UI game object
    I dont know what to do
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;
    public class UIController : MonoBehaviour
    {
    Player player;
    Text distanceText;
    private void Awake()
    {
    player = GameObject.Find("Player").GetComponent();
    distanceText = GameObject.Find("DistanceText").GetComponent();
    }

    // Start is called before the first frame update
    void Start()
    {

    }
    // Update is called once per frame
    void Update()
    {
    int distance = Mathf.FloorToInt(player.distance);
    distanceText.text = distance + " m";
    }
    }

    • @J0hnLedez
      @J0hnLedez 10 หลายเดือนก่อน +2

      I was using the new Text MEsh pro I change my script to include that
      using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;
      using UnityEngine.UI;
      using TMPro;
      public class UIController : MonoBehaviour
      {
      Player player;
      TextMeshProUGUI distanceText;
      private void Awake()
      {
      player = GameObject.Find("Player").GetComponent();
      distanceText = GameObject.Find("DistanceText").GetComponent();
      }

      // Start is called before the first frame update
      void Start()
      {

      }
      // Update is called once per frame
      void Update()
      {
      int distance = Mathf.FloorToInt(player.distance);
      distanceText.text = distance + " m";
      }
      }

    • @NinjaSamuraiJubei
      @NinjaSamuraiJubei 6 หลายเดือนก่อน +1

      @@J0hnLedez very helpful comment thankyou, was getting stuck here. Didn't realize TextMeshPro had its own namespace, thanks again

  • @itswonderdragon2372
    @itswonderdragon2372 2 ปีที่แล้ว

    It says 'The type or namespace 'UI' does not exist in the namespace 'UnityEngine' (are you missing an assembly reference?)'
    I think its to do with the version so please help me fix this (Below is my code)
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;
    public class UIController : MonoBehaviour
    {
    Player player;
    Text distanceText;
    private void Awake()
    {
    player = GameObject.Find("Player").GetComponent();
    distanceText = GameObject.Find("DistanceText").GetComponent();
    }
    // Start is called before the first frame update
    void Start()
    {

    }
    // Update is called once per frame
    void Update()
    {
    int distance = Mathf.FloorToInt(player.distance);
    distanceText.text = distance + " m";
    }
    }

    • @superjustin5000
      @superjustin5000  2 ปีที่แล้ว

      Hmm yea that shouldn't be happening, Have you tried recreating the project? Or just restarting Unity. And are there any other errors in the project?

  • @mwapekalaba7495
    @mwapekalaba7495 9 หลายเดือนก่อน

    I have a problem that says NullReferenceException: Object reference not set to an instance of an object UIController.Update () (at Assets/UIController.cs:26)

  • @alextoma402
    @alextoma402 2 ปีที่แล้ว

    Keep getting this in the console when I run the game :( can't figure out what's wrong
    NullReferenceException: Object reference not set to an instance of an object
    UIController.Update () (at Assets/UIController.cs:28)

    • @superjustin5000
      @superjustin5000  2 ปีที่แล้ว

      Ok, good start. The end of the error message tells you the file and line number to check out. What's on line 28 of UIController.cs ?

    • @divtag1967
      @divtag1967 2 ปีที่แล้ว +1

      @@superjustin5000
      i got the same issue .
      NullReferenceException: Object reference not set to an instance of an object
      UiController.Update () (at Assets/UiController.cs:33)
      this is line 32/33
      int distance = Mathf.FloorToInt(player.distance);
      distanceText.text = distance + " m";