First Person Grid Based Dungeon Crawler Controller in Unity

Поделиться
HTML-код
  • Опубликовано: 31 июл 2024
  • In this video we make a super simple first person controller for a grid based dungeon crawler style game. This style of game has been around since almost the beginning of video games, though there's been something of a resurgence of late.
    The reason I'm making this video is because I am taking part in Dungeon Crawler Jam 2021, a game jam where you have to make this very kind of game. I had to figure out how to do it (though, let's be honest, it's not the most technically challenging thing I've ever done) so I thought I'd share.
    For more details on the jam itself, check out the link below!
    Thanks for watching!
    Chapters:
    0:00 Intro
    0:11 But hwhy?
    0:25 Setup
    1:56 Starting the character controller
    7:01 Input handler
    8:59 Character controller continued
    13:06 Instant movement test
    13:36 Adding smooth movement
    14:41 Smooth movement test
    15:00 Demonstrating collision
    17:27 About Dungeon Crawler Jam 2021
    18:28 Thanking the Patreon
    19:22 Outro
    -----------------------------------------------------------------------------------
    JOIN THE DISCORD SERVER!
    / discord
    -----------------------------------------------------------------------------------
    SUPPORT THE CHANNEL
    The easiest way to support the channel is by liking, subscribing, and sharing. But if you want to go that little bit further, sign up for my Patreon at; / b3agz
    -----------------------------------------------------------------------------------
    LINKS
    Dungeon Crawler Jam 2021: itch.io/jam/dcjam2021
    -----------------------------------------------------------------------------------
    SOCIAL STUFF!
    Website: b3agz.com
    Twitter: / b3agz
    Instagram: instragram.com/b3agz
    #GameJam #DungeonCrawler #MadeWithUnity
  • ИгрыИгры

Комментарии • 81

  • @UlarisBadler
    @UlarisBadler 3 года назад +47

    Hello! I'm the author of Underlair and I'm happy to see you used one of my videos ^^. The instantaneous movement between tiles was only due to of hardware limitations back then. Dungeon Master 2, attempted to mitigate that by adding an in-between-frame as the player moved about. I believe that nowadays, there is not reason not to use animation for the movement. I just want to point out that the animation works best when used with 'easing curves'.
    I also want to share some feedback on how the collision can be done when using Unity for these type of games. Underlair raycast the 4 possible movement directions to check for collisions. I use prefabs with a tagged with a specific name like: Door, Stairs or Wall, all in a layer called 'Collision'. This way, you can assemble levels both procedurally and manually without having to worry about checking for grid coordinates for collision (which is a fine way to do it, mind you) as they are automatically handled by the player's movement function. Cheers!

    • @b3agz
      @b3agz  3 года назад +8

      Thanks for the info! I've pinned your comment for others to see.

    • @UlarisBadler
      @UlarisBadler 3 года назад +4

      @@b3agz Oh thanks! :)

    • @carpii
      @carpii 2 года назад +1

      Under what circumstances would you assemble levels manually in scene editor?. I assumed nearly all levels would just be read from a datafile and then constructed in code?

    • @UlarisBadler
      @UlarisBadler 2 года назад +2

      @@carpii I'm not sure if I'm understood your question. If you are using an engine such as Unity, you probably want to take advantage of its tools to assemble levels visually without coding, that's one of the main reasons you want to use an engine. If you are not using one, you will have to code everything yourself. Regardless the method, levels need to be assembled first, before stored in files.

    • @carpii
      @carpii 2 года назад +1

      @@UlarisBadler ok, thankyou. I wasn't sure whether you would typically write some sort of map editor tool to create the level data files, rather than unity scene editor.

  • @LemSportsinterviews
    @LemSportsinterviews 3 года назад +3

    i've been waiting for a tutorial on this exact topic for ages, thank you so much for getting me started

  • @syrcass
    @syrcass 2 года назад

    thanks to this video, I finally can make my ideal movement which I was digging a week! Thank you.

  • @TKEnvironments
    @TKEnvironments 9 месяцев назад

    Awesome tut, great base to start a game in this genre!

  • @gabrielwhite9881
    @gabrielwhite9881 3 года назад

    Hi, very nice video and your way of solving this example is an good way how someone can handle something like that. Great. Hopefully you will win that jam ;) i like your approaches a lot. :)

  • @_Kolcki
    @_Kolcki 3 года назад +1

    I was looking for a tutorial like this for months now... I'l try it asap. Thanks.

  • @thehuman6646
    @thehuman6646 3 года назад +6

    you can replace
    if (condition) return true;
    else return false;
    with
    return condition

  • @studiomalaka
    @studiomalaka 3 года назад

    Nice man, thanks for sharing!

  • @FlowPoly
    @FlowPoly 3 года назад

    This helped loads man thank you

  • @alanburns9466
    @alanburns9466 4 месяца назад

    Awesome tutorial! Just what I needed.

    • @b3agz
      @b3agz  4 месяца назад

      Glad it helped!

  • @erezmemerbek9155
    @erezmemerbek9155 3 года назад +5

    nice tutorial, keep it up!

  • @reecetarrant5414
    @reecetarrant5414 Год назад

    Hi. I am currently on your video as I am doing the DCJ this year and I wanted to quickly get some prep in. I experimented with the target rotation by setting it to reset to 0 if target rotation is between 270 and 360: It returned to 0, but you couldn't rotate further. Probably better off sticking to 361.0f, as we know that works.
    As for your video as a whole, very good step-by-step process: I like how easily digestible it is as a tutorial. I look forward to seeing more of your content! :)

  • @xezienstudios
    @xezienstudios Год назад

    I would love to see the jam return since it looks like a fun game to make!

    • @b3agz
      @b3agz  Год назад

      The dungeon crawler jam? It's happening in April (I'm entering again this year). itch.io/jam/dcjam2023

    • @xezienstudios
      @xezienstudios Год назад

      @@b3agz Tyy I was wondering if they were doing it again

  • @LongTran-kp3kz
    @LongTran-kp3kz 4 месяца назад

    I love DRPGs. Both the kind where you make your own party and have a very minimalist story a la Wizardry or something, to a more narratively driven one like a good old fashioned, old school SMT game or SMT spinoff. I'd like to make such a game in those styles myself one day, but for now, I think I'm gonna build up some experience with other types of RPGs. One day though. One day. Thanks for the vid. Totally found it by accident!

    • @b3agz
      @b3agz  4 месяца назад +1

      I hope you get to make your game!

    • @LongTran-kp3kz
      @LongTran-kp3kz 4 месяца назад

      @@b3agz
      I'm gonna try anyway!
      Sure I'm in my thirties and late af to the game, but even a bum like me's got stories to tell!

  • @Larkinchance
    @Larkinchance 6 месяцев назад +1

    You mean these dungeons aren't real?
    After FTL Dungeon Master on the Amiga, 35 years later and I'm still hooked

  • @ajoshdroid
    @ajoshdroid 3 года назад +1

    I saw the title, remembered early Elder Scrolls games and let out a guttural oOOooOOO

  • @mads_in_zero
    @mads_in_zero 2 года назад +1

    I recently made something similar to this in Gamemaker Studio 2.
    Turns out, GMS doesn't really support 3D and it's a miracle I got as far as I did.
    But I sure did move the camera over a plane.

  • @squidyouknow
    @squidyouknow 3 года назад +2

    How would I go about implementing a 180 degree turn hotkey with smooth camera transitions? I've gotten it to "work", but my intention is to have it do a full 360 degree turn if it is pressed twice, but instead it just turns counterclockwise, then clockwise again.

  • @collinvisser7108
    @collinvisser7108 2 года назад

    I was keen to do this Jam but this put in me off "The goal is a finished and reasonably polished dungeon crawler; not a prototype, proof of concept or tech demo."
    8 days all I can make is a tech demo - bit of a story - I have a full time job

  • @heehomeboy
    @heehomeboy Год назад +2

    Whenever moving the player's x and z movements are sometimes larger or smaller than just 1 unit. How do you fix this?

  • @jamesbell8148
    @jamesbell8148 2 года назад

    You a dungeon master fan by any chance :)

  • @xSkullzGx
    @xSkullzGx Год назад

    I'm using a Raycast bool in place of your if (Mathf) segment. However, it halts all movement once it detects a Wall. Instead I want it to still allow rotation, or even moving backwards.

  • @omiorahman6283
    @omiorahman6283 2 года назад

    How to create Spell interface and using spells for different players

  • @theodimov
    @theodimov Год назад

    but what do i do if i have 2 walls next to each other? the player goes trough the second wall.

  • @hunterfilippi5400
    @hunterfilippi5400 Год назад

    Can you show how to implement the ui button controls too ?

  • @chaotickclock3071
    @chaotickclock3071 Год назад +1

    Whenever i try to add the playercontroller script to my player object I always get an error saying " Can't add script component 'PlayerController' because the script class cannot be found, Make sure that there are no compile errors and that the file name and class name match. "
    i followed what you wrote perfectly, and yet I am getting errors in the console and the script just isn't working

    • @92Roar
      @92Roar Год назад

      Did you make sure the script name matches the "Required Component" name? If you called the script "playercontroller" and then required "PlayerController" it wont work (case is important!)

  • @velesworth3134
    @velesworth3134 2 года назад

    Could you make tutorial for puzzles ?

  • @asdedoxd
    @asdedoxd 2 года назад +3

    how do i actually do what you said at 15:35 ?, im reaaaally new to coding in unity and i have no idea how to do stuff at all, but im trying my best at doing a dungeon crawler and your code is just perfect, i just dont know how to make it so if theres a wall you dont go thro it.

    • @leejags1
      @leejags1 2 года назад

      Hey, wondering if you ever found out how to do the collision, im currently trying to find a way of doing it but struggling at the moment

    • @softwet525
      @softwet525 2 года назад

      @@leejags1 literally just use raycasting so much easier than creating a grid system

    • @jessicasheldon2855
      @jessicasheldon2855 Год назад

      I know this reply is super late, but I am super new to coding and was also very stuck and disappointed at the lack of explanation on how to check for collisions here.

  • @gardyst9931
    @gardyst9931 Год назад

    If some one can help mine dosen't move ? and I dont know why

  • @Geckotr
    @Geckotr 5 месяцев назад

    thx for the great video. Is there a tutorial for the combat as well?

    • @b3agz
      @b3agz  5 месяцев назад +2

      Not right now but there *could* be if it's something people want to see...

  • @danc01
    @danc01 Год назад

    Where do you set the distance of each movement? In my dungeon it seems to take too many steps to get across a small 3x3 room. 6 key presses to be exact, so how could I change the distance the character moves with each step?

    • @Mborevi
      @Mborevi Год назад

      Did you ever figure this out? I have the same problem..

    • @danc01
      @danc01 Год назад

      @@Mborevi nope

    • @imeldaweijers3284
      @imeldaweijers3284 Год назад +1

      I had the same problem, my grid tiles are 5x5, not 1x1. I solved it by setting a scale float and multiplying everything by that number

  • @otakupengu3880
    @otakupengu3880 Год назад

    targetGridPos = prevTargetGridPos; is always triggering the unreachable code error

  • @daiyahigashikata
    @daiyahigashikata 2 года назад

    while using this code, it works fine, but instead of being placed on exact grid positions i'm ending up on 0.499999 on some positions but not others. can anyone help?

    • @Notir072
      @Notir072 Год назад

      Do:
      position = (float)((int)position) + 0.5f;
      and it will always end with .5

    • @daiyahigashikata
      @daiyahigashikata Год назад

      @@Notir072 ah, thanks for the reply, but i worked it out eventually. i can't remember what i did but it was probably something like that

  • @aetcoolguy
    @aetcoolguy 5 месяцев назад

    For some reason my player doesn't start where I place him, any solution?

    • @b3agz
      @b3agz  5 месяцев назад +1

      The two most obivous things I can think of is check that you've not got duplicate code placing the player and check that your player placement code is offset by the maze position (ie, if you're placing the player at 0,0,0 but the maze parent object is at 10,10,10).

  • @occularmalice
    @occularmalice 2 года назад +1

    The only problem I found with your code (which I don't think you highlight when you're testing it) is that once you turn your .forward vector isn't forward anymore and your MoveForward function is using the wrong values. Turn left and now forward will move you to the left instead of forward. Maybe I'm missing something and got it wrong though.

    • @mr.cynical2201
      @mr.cynical2201 Год назад +1

      Does the code consider direction relative to the dungeon orientation or to the player's orientation? If the former, then I'd say you would need to code a table of information to constantly process the shift in information every 90° around the player's input. If the latter, then the engine parses level state separate from player input making the input relative to the facing direction of the player character. I'm just now being introduced to game creation so I'm not even sure how the engine processes the design code.

    • @Geckotr
      @Geckotr 5 месяцев назад +1

      Same happens to me but not when i turn, it happens when i start the game. w key moves the character backwards, s forward. Left and right keys are reversed for me too.

    • @Geckotr
      @Geckotr 5 месяцев назад +1

      I fixed it. It happens bcs player object's and camera's orientation is wrong, player faces the wrong way in the editor.

  • @revolutionartiste
    @revolutionartiste 2 года назад

    do you still have the source code for this ?

  • @david55200
    @david55200 Год назад

    I want to create a dungeon crawler like Eye of the Beholder in a pixel art style. Do you think it's possible to create 2D monsters and items within this 3D dungeon?"

    • @b3agz
      @b3agz  Год назад

      Yes, creating 2D monster in a 3D space is actually pretty simple in Unity. Just treat a sprite like you would in 2D and have it always face the camera.

    • @david55200
      @david55200 Год назад

      @@b3agz it's not so simple, because creature must to have a right , left and back side too. but i have seen a video on this. i will try it.

  • @BoobnippleXgun
    @BoobnippleXgun Год назад

    This was a great tutorial, right up to the part where you just skipped over collisions. Now, im very new to coding and will either have to figure this out using someone elses code that may not agree with your code, or just undo everything and follow a new tutorial. Im kind of disapointed.

    • @b3agz
      @b3agz  Год назад

      Sorry to hear that. The video covers how to do collisions with a bool (as you would if you were checking against a grid map). If you want to use Unity's physics collisions, it works exactly the same as any other collider check. Replace the bool check in the video with the bool from your collision check.

  • @aaradhyatiwari7428
    @aaradhyatiwari7428 3 года назад

    And first like

  • @ahmetyagz1624
    @ahmetyagz1624 3 года назад

    man, can you please give the Minecraft source code? Please I need it badly

  • @GEGGARCHY
    @GEGGARCHY 3 года назад

    Henlo

  • @cieloazul1205
    @cieloazul1205 3 года назад +3

    I suggest adding “smooth lighting” to your Minecraft game, I would also like to suggest grass and plants.

  • @helloq5051
    @helloq5051 3 года назад

    5th?

  • @thehuman6646
    @thehuman6646 3 года назад

    hello

  • @notafurrysogoaway
    @notafurrysogoaway 3 года назад

    lol

  • @aaradhyatiwari7428
    @aaradhyatiwari7428 3 года назад

    First

  • @notafurrysogoaway
    @notafurrysogoaway 3 года назад

    Second