Ground Collision Raycasting | MAKE AN INFINITE RUNNER game like CANABALT #3 | Unity How to Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 13 ธ.ค. 2024
  • Collision Detection. Fan of ray casting? Or are you more into box collider on box collider action? Comment below!
    Project Files : ko-fi.com/s/75...
    Support/Follow
    Patreon / superjustin5000
    Coffee www.ko-fi.com/...
    Stream / superjustin5000
    Discord / discord
    www.superjusti...
    I also like
    btc - bc1qv6ktxh9kcf6juxjxhqmyjrg6ptv48ptlqu679x
    eth - 0x6b7708Ec9b120c1CA2239c9452060086f83AD9E8
    doge - DKu8DjKL78THAHBz2eh3U9EGQD7QSNnWgM
    Disclaimer: This video assumes you have some beginner knowledge of the Unity IDE. I am using Unity 2021, Visual Studio 2019, and Windows 10 Professional.
    #gamedev #indiegamedev #gamedevelopment #unity3d #unity3d

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

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

    Wow man, just know I am a total newb. So here goes the story today: Did everything like you said (more to that later) and I start the game and everything broke down. I realized it by seeing the background not move. tried to CTRL Z in the script but it went only so far. so i had a mental breakdown and thought about restarting all over without my own sprites but doing exactly as you said it. I came to realization that that might kill my mood so i went back trying to find the error. Then i realized that the distance meter didnt work either and went and saw the character doesnt even move. So i thought, most likely parallax and the distance not working is just the character not moving and then i found the issue. While doing the copy paste and commenting old ground collision system i somewhere made a mistake and put the distance behind a condition. so i moved it out of all conditions but it felt wrong, because he would only accelerate while jumping (maybe an idea for a game lol) so in the end i managed to get it working again. Was really proud with that achievement, even if it was me breaking the script down in the first place.

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

      That's was quite the debugging journey! Taking the time to do that I find are some of the best learning experiences, glad you figured it out.
      Yes gain speed only when on the air, could be a fun concept haha.
      Cheers!

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

    Hey! THANK U for doing this videos, i'm using what i learn to finaly finish someday my own infinite runner game
    Keep up the good work!

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

      Thanks! That's awesome, I can't wait to see how that turns out, you'll have to send it to me.

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

    So well explained that even I understand it hahaha ✌

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

    Nice one Justin! Looking forward to the procedurally generated platforms now :)

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

    Following along every odd morning before work - I'm hoping to have a somewhat working clone that I can slap my own art in as an exercise. Thanks for this, it feels good making an endless runner that isn't kinda garbage or just flappy bird lol EDIT oh shit I see you have a SHMUP game tutorial, damn! Might do that one too someday 'XD

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

      Hahaha thanks for that, I was definitely going for something specific. Cool, I can't wait to see what you come up with.

  • @jessicaspee5992
    @jessicaspee5992 7 หลายเดือนก่อน

    I have followed the script word for word but i keep falling to low instead on the box collider 13:44. Like i put in the calculation, but my character falls into the ground. Idk what im doing wrong, at first i thought the problem was because my characters height was in - numbers and i moved the whole scene up but that also gave me the same problem. So the character is falling to low in the box collider

  • @Readingmangaforfun
    @Readingmangaforfun 4 หลายเดือนก่อน

    i have a problem when i remove the old ground code and implement the new one at a round 6:49 the player stays in one spot and i dont know how to fix that

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

    i have a problem, the player just floats on the platform but still collides with it?

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

    I hope you chanel rise up to 1M subs. I watched many videos about Unity gamedev and can say you make best than they (P.S i use google translation because i can understand what you say, but not have good write skill)

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

    Cool video bro! 😸👍🏽

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

    Is there a benefit of ray casting over box colliders? I want to say you'd be able to do it both ways, but is one objectively better than the other?

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

      In this situation you can do both and it would work just as well. If I were to go back I would probably just use colliders honestly. It works, and I think is way easier for most people to grasp as a collision mechanism.

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

    At 09:45 , your square falls off but mine character does not fall on platform , jump and platform fall is working but not that....initial position is always stuck at that place

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

      Hmm it's possible that the initial values of your y velocity, or isgrounded isn't set correctly?

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

      @@superjustin5000 okay I figured it out , now one last problem is I used a different character Sprite , and when run the game it is inside the walls of platform , how to solve this...

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

      @@animemusic9546 drag that shape down and let the players land on it and see if that works but anything else I have no idea.

    • @reelj.sterakk3566
      @reelj.sterakk3566 ปีที่แล้ว

      @@animemusic9546 How did you fix your first issue ?

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

    can you help. When I jump It jumps step by step like doesn't jump then come down comes one step down when gets out of the border of the ground.cWhat do I do.

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

    I had my ground height set at 10 in the inspector and noticed that the player would snap to that whenever I pressed jump. I changed that to zero and also unchecked the boolean box for is grounded and then the player falls onto the platform. I have a strange but though where the player won't fall off the edge of the platform until I have held jump, otherwise it stays in the same line. When I jump to another platform then suddenly my jump is choked to a smaller/shorter height.

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

    I have a problem with the fact that my character bounces off the "building" in the sense that when I click start then the character bounces off him instead of standing on the building, please help me

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

      Continuously bouncing up and down, while moving across the building? If so, something could be off in the ground height, or the length of the raycasts is my initial guess.

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

      Vector2 rayOrigin = new Vector2(pos.x + 0.7f, pos.y);
      Vector2 rayDirection = Vector2.up;
      float rayDistance = velocity.y * Time.fixedDeltaTime;
      RaycastHit2D hit2D = Physics2D.Raycast(rayOrigin, rayDirection, rayDistance);
      if (hit2D.collider != null)
      {
      Ground ground = hit2D.collider.GetComponent();
      if (ground != null)
      {
      pos.y = hit2D.point.y;
      isGrounded = true;
      }

      }
      in this part you have to change pos.y = groundHeight to hit2D.point.y;
      Sorry a bit late but perhaps you could use :)

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

    I don't have the GetComponent Ground. I am on 2021 version, does it have something to do with that? Minute 6:49

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

      GetComponent is pretty standard. Make sure you have "using UnityEngine;" at the top of the script. Sometimes the code editor can get out of sync and you have to restart everything.

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

    just finished 10:10 and my character is floating above the ground. Do you know how i could fix this? thx

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

      Potentially something off in the collider size and position of the ground objects. That's what the ground height is calculated from.

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

      @@superjustin5000 I had to switch it to be divided by 5, don't know how that happened. Thanks for the help.

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

    I followed the instructions of this section step by step, but when I press the play button, nothing is executed, why?
    The codes don't work.

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

    Something makes the groundHeught 20.1 one every time i land?

  • @vinivini-o8m
    @vinivini-o8m 3 ปีที่แล้ว

    Thank You !!!!

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

    i seem to have a problem, after i erased the older grounding function still keeps stopping at the groundHeigth value.

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

      correction, i seem to enter the collider and then i cannot jump because im inside

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

      You should still be able to jump. Unless the jump height is so small that you're falling before exiting the collider.

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

    how do you get the black outlines around the sprites?

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

      Those outlines are part of the default sprite I was using that Unity provides. I wonder if newer Unity versions don't have it.

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

    Is the character actually moving horizontally because I am trying to implement a similar feature and my character moves to the right but the camera stays in the same position.

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

      Nah, it's an illusion, the background is just scrolling by over and over, while the character stays in the same X position forever.

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

    Hi, i follow the code one by one and it works until the raycast part. I wonder why does my player fall through the y axis after applying the raycast line. Hope you can help with this

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

      Could be a number of things really. The 'Y' position isn't correctly calculated, the rigidbody is missing or misconfigured.

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

    ı have a error on 07.54 Assets\Player.cs(72,37): error CS1729: 'Vector2' does not contain a constructor that takes 3 arguments can u guys help me?

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

      Can you share the line of code that contains the error?

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

    In low fps player automatically falls down even into the ground

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

    My raycast3D only works when object goes up from below with negative gravity, why may that be?

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

      Depends on either how your setting the ray cast direction/distance, or maybe the logic for when ray casts should happen. But I'd have to see the code to be sure. You're welcome to send me the files. Is everything else about the jumping working?

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

      @@superjustin5000 Hey thanks for reply, well logic is pretty much the same but I'm lost after raycast. I will be sending it to your email

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

      @@superjustin5000 ok so when i changed the rayDistance to negative, it was able to detect the ground to collide however now it wont fall if i dont jump off of ground.

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

      Ok I see now. Since you're doing 3D raycasts instead of 2D, it seems that they work differently in terms of how you are allowed to define direction and distance.
      In my project I set the direction to up, and used the distance as y velocity directly because that would make it point down since it was negative.
      In your project, the 3D raycast seems to only work if the distance is positive. So use Mathf.Abs(rayDist) and set the direction to Vector3.down.
      Strange the it handles these things differently in 2d vs 3d, but those are my findings so far.

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

      @@superjustin5000 yes its weird 3D returns bool theyre very different. I’ve tried Vector.down but it didn’t help, i will try absolute value though thanks!

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

    Whats mean with: ,, (Ground) doesn‘t contain a definition for (groundHeight) ?

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

      There should be a variable defined inside the class/script called 'Ground'. And it should be named 'groundHeight'.
      That's assuming you're trying to access it from somewhere else like the Player class.

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

      Honestly I’m having the same issue

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

    this series is really cool, thanks for sharing. i have a problem when i try to reset the velocity.y my player bugs out and jitters up and down close to the ground height :/ anyone with any ideas?

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

      i ended up with a solution to make it reset at the if (hit2D.collider == null) section, which i guess does the trick..

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

      Yo! Nice. I call this a custom solution. Sometimes the things we do in the player controller can seem "hacky", but we have to do what makes the game feel how it's supposed to, as long as it's consistent.

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

      @@deankemball8084 I bless you for your comment, I was trying to fix this for hours you saved me hahaha

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

    Ayo for some reason when I have the same velocity and max velocity as you my buildings move like 500000 times faster than yours do, I have checked my scripts and cant find anything wrong.

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

      Check if the properties in the inspector might be different when you select the game object in the scene. If a public property of a script has one value, and it's already attached to something in the scene, changing the default value in the script will not update the value on the game object.
      Another thing to check out would be the sizing of the camera and scene, to see if there are differences, though that probably won't account for 5 million times difference ha.