Unity Create a Game Series (E10. map connectivity)

preview_player
Показать описание
In episode ten we ensure full map connectivity using a simple flood-fill algorithm.

Source code:

Follow me on twitter @SebastianLague
Рекомендации по теме
Комментарии
Автор

Just a small nice to have optimization for our MapIsFullyAccessible method:
instead of using
if (x==0 || y ==0)
we can use:
if (x==0 ^ y==0) (using the XOR operator instead)
that way, we'll skip the current tile (:

Great tutorial keep going!

oronbz
Автор

Hi, thank you for this great tutorial series.
I know it's been a while since you did it but I wanted to add something for those who might end up follow it now.
When you override the == and != operators you can add the code below to get rid of the warning on the struct :
public override bool Equals(object obj)
{
if (obj is Coord coord)
{
return this == coord;
}

return false;
}

public override int GetHashCode() => new { x, y }.GetHashCode();

MDE
Автор

A friendly reminder that you can support my videos on Patreon ;)

I hope you enjoy the video! Next episode we'll probably be incorporating the map generator into our game scene.

SebastianLague
Автор

If you keep getting "out of range" errors even with integer sizes, like i was, make sure all the X and Ys on this line here are correct:
if (neighbourX >= 0 && neighbourX < obstacleMap.GetLength(0) && neighbourY >= 0 && neighbourY < obstacleMap.GetLength(1))

Just throwing it in here if anyone encounters the same issue!
Thanks again for these great tutorials! And thanks commenters for helping as well!

jkRatbird
Автор

16:02 Like this when you get two Yellow Errors, you can solve by putting this code in "public struct Coord"

public override bool Equals(object obj)
{
return base.Equals(obj);
}
public override int GetHashCode()
{
return base.GetHashCode();
}

jomg_
Автор

Not Advanced video, This is EPIC one episode in the whole series.

beaverjoe
Автор

Hey I'm doing the series in 2017, awesome tutorials!!
This and the last episode changed my definitions of advanced programming hahaha
Keep up the good work buddy!

pedrosantos
Автор

I am already so excited about the next episode. Please keep up the good work!

McLumx
Автор

That is just brilliant, very clever. I will be supporting you after my next pay day!

paulbraddick
Автор

If anyone is confused about the MapIsFullyAcessible function. This is pretty much a variation of Breath First Search algorithm. You can find more details online. This is for you non-CS folks who just wants to make games.

jontran
Автор

Hi Sebastian, thank you for all your wonderful tutorials!! My dream is to become a great developer as you.. but after watching this tutorial I got really confused, I mean, how do you manage that big bunch of code ? D: Do you remember all of it ? It was a lot of stuff.. I hope you will answer me :l Cheers!

HB-wkzj
Автор

ok, this is maybe the best tutorial i have see in Unity but the last part was so difficult. I maybe can never do this by myself.

tomasabad
Автор

I know this comment is late but I wanted to know where you lernt programming because you are so good

ClemensWolfmayr
Автор

Awesome video series, such a great presentation.

Found a few concerns though. If you raise your mapSize to say 100x100 the editor script on my computer seems to freeze. I found if i booted up my editor of choice you can edit the project file and remove the Map-generation from the editor which eliminates the problem when you reboot Unity.

IN this regard is there a way to reduce the scope of the obstacle generation so that its not so resource intense. Sure I have a few ideas, but limiting this series to your code, until your done, than I'll prob factor in so many of your other great videos!

micaiahstevens
Автор

Thank you, you are very very good teacher

살인상생
Автор

Thanks Sebastian, for the awesome tutorials!
I found a problem in this episode, so when generating obstacles, if the random position does not meet the accessible condition, we just mark it as false and decrease current obstacle number. In this case there may be such a situation that we want 10 obstacles to be created, but we end up with only 9 because one of them doesn't meet the accessible condition.
so instead of using the for loop, how about saying while(currentObstacles < obstacleCount){...} ?

qizzz
Автор

Блин, как же хорошо, что в современных версиях Unity есть структура Vector2Int )

skarabeydm
Автор

It's really awesome . Really helpful to me. thx!

우윳빛깔케라스
Автор

Wow, I wasted about 15 hours trying to define enclosures on a grid and ended up with a huge mess because I didn't know about queues. Thank you! Quick question though: My game is using a 50x50 grid and halts for several seconds whenever I call this function. Any suggestions for optimization?

robertmehring
Автор

Hey Sebastian is there a reason you decided to use Vector2 for mapsize instead of Vector2Int? Wouldn't that prevent some of the issues?

trapshooter