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 Игры
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!
Thanks for the info! I've pinned your comment for others to see.
@@b3agz Oh thanks! :)
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?
@@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.
@@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.
i've been waiting for a tutorial on this exact topic for ages, thank you so much for getting me started
thanks to this video, I finally can make my ideal movement which I was digging a week! Thank you.
Awesome tut, great base to start a game in this genre!
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. :)
I was looking for a tutorial like this for months now... I'l try it asap. Thanks.
you can replace
if (condition) return true;
else return false;
with
return condition
Nice man, thanks for sharing!
This helped loads man thank you
Awesome tutorial! Just what I needed.
Glad it helped!
nice tutorial, keep it up!
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! :)
I would love to see the jam return since it looks like a fun game to make!
The dungeon crawler jam? It's happening in April (I'm entering again this year). itch.io/jam/dcjam2023
@@b3agz Tyy I was wondering if they were doing it again
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!
I hope you get to make your game!
@@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!
You mean these dungeons aren't real?
After FTL Dungeon Master on the Amiga, 35 years later and I'm still hooked
I saw the title, remembered early Elder Scrolls games and let out a guttural oOOooOOO
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.
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.
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
Whenever moving the player's x and z movements are sometimes larger or smaller than just 1 unit. How do you fix this?
You a dungeon master fan by any chance :)
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.
How to create Spell interface and using spells for different players
but what do i do if i have 2 walls next to each other? the player goes trough the second wall.
Can you show how to implement the ui button controls too ?
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
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!)
Could you make tutorial for puzzles ?
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.
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
@@leejags1 literally just use raycasting so much easier than creating a grid system
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.
If some one can help mine dosen't move ? and I dont know why
thx for the great video. Is there a tutorial for the combat as well?
Not right now but there *could* be if it's something people want to see...
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?
Did you ever figure this out? I have the same problem..
@@Mborevi nope
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
targetGridPos = prevTargetGridPos; is always triggering the unreachable code error
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?
Do:
position = (float)((int)position) + 0.5f;
and it will always end with .5
@@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
For some reason my player doesn't start where I place him, any solution?
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).
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.
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.
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.
I fixed it. It happens bcs player object's and camera's orientation is wrong, player faces the wrong way in the editor.
do you still have the source code for this ?
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?"
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.
@@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.
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.
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.
And first like
man, can you please give the Minecraft source code? Please I need it badly
Henlo
I suggest adding “smooth lighting” to your Minecraft game, I would also like to suggest grass and plants.
5th?
hello
lol
First
Second