Master Grid Placement in Unity 2022 P1 - Calculating Cell Position

In this Unity 3D tutorial start creating a Grid Building System. First we will use Grid component to calculate a cell position for our mouse pointer position to use it in our placement system. Next we will expend the system with a custom grid shader and an object placement and removal system. At the end of this tutorial you will have a grid placement system that you can use in your own project.
House building system in unity project template:
courses.sunnyvalleystudio.com...
Starter Project:
/ 80441380
Scripts on github:
github.com/SunnyValleyStudio/...
Assets used:
kenney.nl/
𝗛𝗮𝘃𝗲 𝗮𝗻𝘆 𝗾𝘂𝗲𝘀𝘁𝗶𝗼𝗻𝘀? 𝗝𝗼𝗶𝗻 𝘁𝗵𝗲 𝗱𝗶𝘀𝗰𝗼𝗿𝗱!
/ discord
𝗣𝗟𝗘𝗔𝗦𝗘 support the channel:
/ sunnyvalleystudio
00:00 Grid system
00:30 Starter Project
01:00 Getting Mouse position on a plane
03:10 Placement System
05:20 Testing getting mouse position
05:50 Grid Component
08:11 Getting Grid Cell Position
09:36 Testing Grid Cell Selection
10:08 Adjusting offset for the Grid component
#unity3d #gamedevelopment #indiegamedev #sunnyvalleystudio

Пікірлер: 249

  • @SunnyValleyStudio
    @SunnyValleyStudio Жыл бұрын

    Part 2 about grid visualization -> kzread.info/dash/bejne/oH96lrKwkpCcf9o.html

  • @rongreen385
    @rongreen385 Жыл бұрын

    I wasn't having much luck finding good examples of using Unity's Grid class and along comes your tutorial - yay! Thank you so much.

  • @SunnyValleyStudio

    @SunnyValleyStudio

    Жыл бұрын

    Glad it was helpful! 👍

  • @MuhammadBilal-cs3dg

    @MuhammadBilal-cs3dg

    Жыл бұрын

    @@SunnyValleyStudio can you please share the starter project link

  • @This-Was-Sparta
    @This-Was-Sparta Жыл бұрын

    Great stuff as always. Exactly what I was looking for.

  • @SunnyValleyStudio

    @SunnyValleyStudio

    Жыл бұрын

    Thanks 👍

  • @Berndr
    @Berndr11 ай бұрын

    Really great and clear strait forward explanation!

  • @SunnyValleyStudio

    @SunnyValleyStudio

    11 ай бұрын

    Thanks for watching 👍

  • @zeggxr1539
    @zeggxr1539 Жыл бұрын

    really excited to watch it, thanks for the great tutorials!!

  • @SunnyValleyStudio

    @SunnyValleyStudio

    Жыл бұрын

    Thanks!

  • @frmlsshrmn
    @frmlsshrmn Жыл бұрын

    This is extremely useful. I've been trying to get started on a base-building game and what I want to accomplish first is to make it possible to plop down objects (buildings) of various dimensions (1x1, 2x3) on a grid. So I'm looking forward to the rest of the series. Thanks!

  • @SunnyValleyStudio

    @SunnyValleyStudio

    Жыл бұрын

    Awesome! I will be posting the remining parts this week.

  • @MuhammadBilal-cs3dg

    @MuhammadBilal-cs3dg

    Жыл бұрын

    @@SunnyValleyStudio can you please share the starter project link

  • @scjohnson243
    @scjohnson2437 ай бұрын

    Really useful, been trying to follow one of these and have not had much luck, so far this one is great!

  • @SunnyValleyStudio

    @SunnyValleyStudio

    7 ай бұрын

    Great to hear! Thanks for watching 🙂

  • @ItsPBUH
    @ItsPBUH11 ай бұрын

    These are great tutorials, always love your content :)

  • @SunnyValleyStudio

    @SunnyValleyStudio

    11 ай бұрын

    Thanks a lot 🙂

  • @Tozerus1
    @Tozerus1 Жыл бұрын

    Thank you for the great tutorial!

  • @SunnyValleyStudio

    @SunnyValleyStudio

    Жыл бұрын

    Thanks for watching 🙂

  • @Chigamungus
    @Chigamungus3 ай бұрын

    Fantastic tutorial! Exactly the kinds of things I was hoping to learn

  • @SunnyValleyStudio

    @SunnyValleyStudio

    3 ай бұрын

    Glad to hear it! 🙂

  • @bane9109
    @bane9109 Жыл бұрын

    Hey Peter, thanks for this tutorial! Grid system is something i’ve had trouble with in the past, so I’m looking forward to learning how to implement this

  • @SunnyValleyStudio

    @SunnyValleyStudio

    Жыл бұрын

    I hope that my tutorial will help 🙂

  • @MuhammadBilal-cs3dg

    @MuhammadBilal-cs3dg

    Жыл бұрын

    @@SunnyValleyStudio can you please share the starter project link

  • @Joseph-ud1sd
    @Joseph-ud1sd Жыл бұрын

    This Video helped me a lot! Thank you!

  • @SunnyValleyStudio

    @SunnyValleyStudio

    Жыл бұрын

    Thank you!

  • @eldarkvadrat
    @eldarkvadrat Жыл бұрын

    You doing good job via tutorials. Glad to watch it :)

  • @SunnyValleyStudio

    @SunnyValleyStudio

    Жыл бұрын

    Glad you like them!

  • @MuhammadBilal-cs3dg

    @MuhammadBilal-cs3dg

    Жыл бұрын

    @@SunnyValleyStudio can you please share the starter project link

  • @user-kv2hl6ij5h
    @user-kv2hl6ij5h Жыл бұрын

    Thank's man. That just what I've been looking for

  • @SunnyValleyStudio

    @SunnyValleyStudio

    Жыл бұрын

    Awesome! 🙂

  • @gabrielzanoni9961
    @gabrielzanoni9961 Жыл бұрын

    Thank you very much! You teaching skills are awesome!

  • @SunnyValleyStudio

    @SunnyValleyStudio

    Жыл бұрын

    Thanks for watching 🙂

  • @harzall
    @harzall Жыл бұрын

    I've never thought to use the Unity Grid component all this long... seems very useful now

  • @SunnyValleyStudio

    @SunnyValleyStudio

    Жыл бұрын

    Thanks for the comment!

  • @yuhochih
    @yuhochih3 ай бұрын

    Thank you for making this tutorial, it is really helpful to me

  • @SunnyValleyStudio

    @SunnyValleyStudio

    3 ай бұрын

    You're welcome 😊

  • @WEB2TV
    @WEB2TV Жыл бұрын

    This is wonderful tutorial! Thank you!!

  • @SunnyValleyStudio

    @SunnyValleyStudio

    Жыл бұрын

    Thanks for watching 🙂

  • @MuhammadBilal-cs3dg

    @MuhammadBilal-cs3dg

    Жыл бұрын

    @@SunnyValleyStudio can you please share the starter project link

  • @wasifalmeem4651
    @wasifalmeem46519 ай бұрын

    Thanks a lot, really simple and straight forward. used prebuild unity components with a really simple logic. Thanks a lot brother

  • @SunnyValleyStudio

    @SunnyValleyStudio

    9 ай бұрын

    Thanks!🙂

  • @ender_0967
    @ender_0967 Жыл бұрын

    ❤ Thanks Peter, this tutorial is fantastic, It helped a lot!

  • @SunnyValleyStudio

    @SunnyValleyStudio

    Жыл бұрын

    Glad it helped! 👍

  • @MuhammadBilal-cs3dg

    @MuhammadBilal-cs3dg

    Жыл бұрын

    @@SunnyValleyStudio can you please share the starter project link

  • @halimebeyzacicek8440
    @halimebeyzacicek844010 ай бұрын

    A very clear and entertaining video.

  • @SunnyValleyStudio

    @SunnyValleyStudio

    9 ай бұрын

    Glad you enjoyed it!

  • @RavenG102
    @RavenG1025 ай бұрын

    its a good start for my ideas, thanks!

  • @SunnyValleyStudio

    @SunnyValleyStudio

    5 ай бұрын

    Good to hear that! 👍🙂

  • @ranggasukandar3533
    @ranggasukandar353310 ай бұрын

    Thanks! super easy to understand👍

  • @SunnyValleyStudio

    @SunnyValleyStudio

    10 ай бұрын

    Glad to hear that! 👍

  • @deibysantiago9639
    @deibysantiago96398 ай бұрын

    thank you sunny, amazing tuts

  • @SunnyValleyStudio

    @SunnyValleyStudio

    8 ай бұрын

    Thanks for watching 🙂

  • @jboadas
    @jboadas4 ай бұрын

    Thanks for the video, very useful.

  • @SunnyValleyStudio

    @SunnyValleyStudio

    4 ай бұрын

    Thanks for watching! 👍

  • @farvardinmainyu1961
    @farvardinmainyu1961 Жыл бұрын

    Thank you Peter !

  • @SunnyValleyStudio

    @SunnyValleyStudio

    Жыл бұрын

    Thanks for watching 🙂

  • @minhquandam7334
    @minhquandam733411 ай бұрын

    You are my savior !!! Thanks for the video

  • @SunnyValleyStudio

    @SunnyValleyStudio

    11 ай бұрын

    Thanks for watching 🙂

  • @zubairGamX
    @zubairGamX9 ай бұрын

    Just Amazing Sir

  • @SunnyValleyStudio

    @SunnyValleyStudio

    9 ай бұрын

    Thanks a lot!

  • @aciloaicilo2926
    @aciloaicilo2926 Жыл бұрын

    really helpful video, thanks

  • @SunnyValleyStudio

    @SunnyValleyStudio

    Жыл бұрын

    Thanks for watching!

  • @TheAlliones
    @TheAlliones8 ай бұрын

    Great Video!

  • @SunnyValleyStudio

    @SunnyValleyStudio

    8 ай бұрын

    Thanks!

  • @askdailyfact7529
    @askdailyfact75296 ай бұрын

    amazing and easy tutorials

  • @SunnyValleyStudio

    @SunnyValleyStudio

    6 ай бұрын

    Thanks for watching! 👍

  • @troyna77
    @troyna7711 ай бұрын

    thanks a lot !!! i always learn when watching you tutorials. I really enjoy your udemy courses.

  • @SunnyValleyStudio

    @SunnyValleyStudio

    11 ай бұрын

    I really appreciate that! Thanks for watching 🙂

  • @clintonhamil9371
    @clintonhamil93713 ай бұрын

    Thanks! Using this in a Game Jam build right now :D

  • @SunnyValleyStudio

    @SunnyValleyStudio

    3 ай бұрын

    Awesome! Let me know how it went! 🙂

  • @FrogKin9
    @FrogKin97 ай бұрын

    Thank you - again... Great work and alyways exactly what I'm looking for. As soon as I (or if I ever) earn some money with my Games, I will support you financially as well.

  • @SunnyValleyStudio

    @SunnyValleyStudio

    7 ай бұрын

    Thanks. And be sure to focused on making games first 👍 Making money from games is kind of separate skill and I don't think it is easy to learn it and make games at the same time 🙂

  • @ayyycortana7196
    @ayyycortana71964 ай бұрын

    Thanks for the video :)

  • @SunnyValleyStudio

    @SunnyValleyStudio

    4 ай бұрын

    Thanks for watching!

  • @vvbgamedevx11
    @vvbgamedevx11Ай бұрын

    Thanks for the tutorial looking for something like this....

  • @SunnyValleyStudio

    @SunnyValleyStudio

    Ай бұрын

    Great to hear! Thanks for watching 🙂

  • @graheet
    @graheet6 ай бұрын

    You wonderful man. Thank you very much.

  • @SunnyValleyStudio

    @SunnyValleyStudio

    6 ай бұрын

    Thanks 👍

  • @gamedevbaiyi936
    @gamedevbaiyi936 Жыл бұрын

    Love it.✌

  • @SunnyValleyStudio

    @SunnyValleyStudio

    Жыл бұрын

    Thanks for watching 🙂

  • @ShahanAkhter
    @ShahanAkhter11 ай бұрын

    thanks awesome tutorial

  • @SunnyValleyStudio

    @SunnyValleyStudio

    11 ай бұрын

    Thanks for witching! 👍

  • @back2back712
    @back2back712Ай бұрын

    thank you sooooo much big brother

  • @SunnyValleyStudio

    @SunnyValleyStudio

    Ай бұрын

    Thanks for watching!

  • @bluzenkk
    @bluzenkk Жыл бұрын

    cool and thanks~~ looks better and better~

  • @SunnyValleyStudio

    @SunnyValleyStudio

    Жыл бұрын

    Thanks for watching 🙂

  • @user-in4gk8lm7q
    @user-in4gk8lm7q Жыл бұрын

    Great video)

  • @SunnyValleyStudio

    @SunnyValleyStudio

    Жыл бұрын

    Thanks!

  • @amenalaya1417
    @amenalaya14178 ай бұрын

    Thanks nice one

  • @SunnyValleyStudio

    @SunnyValleyStudio

    7 ай бұрын

    Glad to hear it!

  • @ianfavreau9776
    @ianfavreau97762 ай бұрын

    To anyone having trouble with the Mouse Indicator Testing part, make sure you have a mesh collider on the plane you are using as your grid. Also, to anyone having trouble with the Cursor Indicator not aligning with the cursor, make sure it has the correct Y position as it is different in the game than in the scene viewport. Spend time to make sure it is perfectly level in the game when you hit play (it doesn't matter if it is below the plane in the scene mode).

  • @SunnyValleyStudio

    @SunnyValleyStudio

    2 ай бұрын

    Thanks for sharing! 👍

  • @jeremylock199
    @jeremylock199 Жыл бұрын

    Thanks a lot for this Peter. I really want a grid building system for my tank game (actually using your tutorial for that too). I want to reimagine the game Bolo on the Apple II.

  • @SunnyValleyStudio

    @SunnyValleyStudio

    Жыл бұрын

    Sounds awesome! Be sure to share your progress on SVS discord (link in every video) 🙂

  • @MuhammadBilal-cs3dg

    @MuhammadBilal-cs3dg

    Жыл бұрын

    @@SunnyValleyStudio can you please share the starter project link

  • @Reykoil
    @Reykoil8 ай бұрын

    THX!

  • @SunnyValleyStudio

    @SunnyValleyStudio

    8 ай бұрын

    Thanks for watching! 🙂

  • @walterpalladino1965
    @walterpalladino1965 Жыл бұрын

    Thanks!!!

  • @SunnyValleyStudio

    @SunnyValleyStudio

    Жыл бұрын

    Thanks for watching 🙂

  • @aleqkzander
    @aleqkzander2 ай бұрын

    Thanks :)

  • @SunnyValleyStudio

    @SunnyValleyStudio

    2 ай бұрын

    Thanks for watching! 👍

  • Жыл бұрын

    Your videos are amazing please share more video 😊😊😊😊😊😊😊😊

  • @SunnyValleyStudio

    @SunnyValleyStudio

    Жыл бұрын

    Thanks for watching 🙂

  • @NecmonRed
    @NecmonRed9 ай бұрын

    Thank you! I'm not a native british or american, but i understood all frazes or words. My english level not low, and not high. The most best part of your tutorial is code. U make code so easy that hard to didn't undrestand what happen in video. One more - Thank you! +rep

  • @SunnyValleyStudio

    @SunnyValleyStudio

    9 ай бұрын

    Thanks for the comment!

  • @bsdrago
    @bsdrago Жыл бұрын

    Great!

  • @SunnyValleyStudio

    @SunnyValleyStudio

    Жыл бұрын

    Thanks!

  • @jessepaulsen973
    @jessepaulsen9735 ай бұрын

    Great vid. By the way this creator also has courses on Udemy. Several of the courses are great for people who have got the fundamentals of Unity and coding under their belt and need to start learning architecture, design patterns and internal testing.

  • @SunnyValleyStudio

    @SunnyValleyStudio

    5 ай бұрын

    Thanks for watching!

  • @user-gn4gy9fl9y
    @user-gn4gy9fl9y5 ай бұрын

    Thanks m8!

  • @SunnyValleyStudio

    @SunnyValleyStudio

    5 ай бұрын

    Thanks for watching!

  • @MuhammadBilal-cs3dg
    @MuhammadBilal-cs3dg Жыл бұрын

    Awesome

  • @SunnyValleyStudio

    @SunnyValleyStudio

    Жыл бұрын

    Thanks!

  • @vasilijemilenkovic1069
    @vasilijemilenkovic10694 ай бұрын

    Great vidio

  • @SunnyValleyStudio

    @SunnyValleyStudio

    4 ай бұрын

    Thanks for watching! 🙂

  • @zararyounis7723
    @zararyounis77235 ай бұрын

    Thanks

  • @SunnyValleyStudio

    @SunnyValleyStudio

    5 ай бұрын

    Thanks for watching!

  • @Sakuno-
    @Sakuno-6 ай бұрын

    감사합니다.

  • @SunnyValleyStudio

    @SunnyValleyStudio

    6 ай бұрын

    시청해 주셔서 감사합니다.

  • @user-fn4pg3bt3g
    @user-fn4pg3bt3g9 ай бұрын

    I`m trying to adapt your lecture for 2D Unity System. This lecture is so perfect for me and your last explanation for pivot makes me know why my tilemap dislocated little. Thank you. Let me ask you one more question... I think I can alternate Grid Component to Tilemap Component because we usually use it in 2D unity, and it is OK until but... do you think is there potential problems?

  • @SunnyValleyStudio

    @SunnyValleyStudio

    9 ай бұрын

    Hey! Tilemap in unity either inherits or uses grid component. I think it uses it because you get the grid component added whenever you create a tilemap. I think you can use either one.

  • @CLAREBPED
    @CLAREBPED11 ай бұрын

    esse curso me ajuda muito com meus estudos, obrigado!

  • @SunnyValleyStudio

    @SunnyValleyStudio

    11 ай бұрын

    Thanks for witching 🙂

  • @kilauroombrand5721
    @kilauroombrand57216 ай бұрын

    thanks

  • @SunnyValleyStudio

    @SunnyValleyStudio

    6 ай бұрын

    Thanks for watching 🙂

  • @81gamer81
    @81gamer816 ай бұрын

    good stuff comment

  • @SunnyValleyStudio

    @SunnyValleyStudio

    6 ай бұрын

    Thanks!

  • @richiebee33
    @richiebee338 күн бұрын

    Just what the doctor ordered! I can't wait to use this in the game. I'll definitely be buying your course. One question: my game is currently using Unity 2021. Is it a must to upgrade to 2022?

  • @SunnyValleyStudio

    @SunnyValleyStudio

    6 күн бұрын

    As long as you are using Unity 2021.2 and above there should be no issues. This is because I am using C#9 features docs.unity3d.com/2021.2/Documentation/Manual/CSharpCompiler.html I am not sure about the shader part since this changes a lot (we are using a shader graph). But its something that you can convert easily - well you would recreate the shader in the older version of shader graph if it doesn't work out of the box). So those are the only limitations that comes to mind.

  • @Whush69
    @Whush695 ай бұрын

    thx

  • @SunnyValleyStudio

    @SunnyValleyStudio

    5 ай бұрын

    Thanks for watching!

  • @Whush69

    @Whush69

    5 ай бұрын

    @@SunnyValleyStudio This really helped me, I'm making a Tower Defence game in 3D and i needed the grid for it!

  • @heiswatchingus
    @heiswatchingus10 ай бұрын

    After this tutorial I'll be a phucking billionare!

  • @CLAREBPED
    @CLAREBPED11 ай бұрын

    muito bom!

  • @SunnyValleyStudio

    @SunnyValleyStudio

    11 ай бұрын

    Thanks 👍

  • @mcredbunny5542
    @mcredbunny55423 ай бұрын

    Thanks for the tutorial but where is the project you mentioned at the start of the video?

  • @SunnyValleyStudio

    @SunnyValleyStudio

    3 ай бұрын

    If you mean the extended version you can find it here courses.sunnyvalleystudio.com/ . Thanks for your support! 😍

  • @dukemagus
    @dukemagus Жыл бұрын

    That's a good tutorial. Do you make guides for different engines or it's an Unity-focused channel??

  • @SunnyValleyStudio

    @SunnyValleyStudio

    Жыл бұрын

    Hey! Right now (this channel) is Unity focused. I want to do something similar for Godot in the near future. No plans for other engines though 🙂 BTW many people have mentioned that some of the Procedural generation tutorials of mine are easily portable to Unreal engine. Code logic / architecture can easily be reused between engines. Things like Unity specific components (like the Grid component here) might be harder to translate though.

  • @starfart69
    @starfart698 ай бұрын

    When you say you can change it to hexagon in @7:15, it would be so much better to watch if you click it just to show the viewer what changes if you do that.

  • @SunnyValleyStudio

    @SunnyValleyStudio

    8 ай бұрын

    Thanks for the feedback! 👍

  • @starfart69

    @starfart69

    8 ай бұрын

    @@SunnyValleyStudio Hey, you have great content man. Your subs are criminally underrated.

  • @bollyfun5963
    @bollyfun59635 ай бұрын

    thnks

  • @SunnyValleyStudio

    @SunnyValleyStudio

    5 ай бұрын

    Thanks for watching!

  • @gheazu6954
    @gheazu69544 ай бұрын

    ty

  • @SunnyValleyStudio

    @SunnyValleyStudio

    4 ай бұрын

    Thanks for watching! 🙂

  • @jaybehl7567
    @jaybehl756711 ай бұрын

    Hi, when I import the project assets (i only import the ones needed for the prefabs) the "CursorIndicatorParent" only shows as a opaque blank white square. It doesnt have the transparent hole in the center it does like yours. I am using Unity 2022.3.0. Can u help me? Otherwise, fantastic tutorial!

  • @SunnyValleyStudio

    @SunnyValleyStudio

    11 ай бұрын

    Maybe you have to set the "Render Mode" to be Transparent in the Material for the Cursor object docs.unity3d.com/Manual/StandardShaderMaterialParameterAlbedoColor.html

  • @danieletacconi5140

    @danieletacconi5140

    4 ай бұрын

    @@SunnyValleyStudio Ti sto seguendo ora e se permetti provo a aiutare riguardo alla domanda anche se nella mia lingua. Seleziona il materiale cellIndicator, in alto a destra cambia lo shader in standard. A questo punto doce c'è albedo ci metti lo sprite GridInidcator che trovi nella cartella _content. Fatto ciò basta che rimetti lo shader in sprites/default e dovresti visualizzare perbene. Ottimo video

  • @watercat1248
    @watercat12487 ай бұрын

    This remindmy Sims 11:45 especially this part

  • @SunnyValleyStudio

    @SunnyValleyStudio

    7 ай бұрын

    Awesome! I hoped it would 🙂 (otherwise I don't think people would watch the tutorial that much 😅)

  • @watercat1248

    @watercat1248

    7 ай бұрын

    @@SunnyValleyStudio enway I'm sure I bulding editor like I will be able to be useful for other type off game's well. It will be easy to make Sothis like this as map editor for game. Or a one off the tools for sandbox game.

  • @LDnbi
    @LDnbi10 ай бұрын

    Hey, great tutorial, though I am having problems with the sphere moving towards the screen when the mouse is stationary. Checked the code and it seems to be the same, not sure if you may know why this is happening?

  • @LDnbi

    @LDnbi

    10 ай бұрын

    Okay, I figured it out and it's so obvious now I have. I just hadn't changed the layer of the sphere, so the ray wasn't touching the plain.

  • @SunnyValleyStudio

    @SunnyValleyStudio

    10 ай бұрын

    I'm glad that you have found and fixed the issue 👍

  • @mikeaelmich
    @mikeaelmich7 ай бұрын

    Maybe you have tutorial on generating a house based on outlines on a satellite map. So that users can draw the shape of their house and apply extrude

  • @SunnyValleyStudio

    @SunnyValleyStudio

    7 ай бұрын

    Not yet! Sorry 🙂

  • @mikeaelmich

    @mikeaelmich

    7 ай бұрын

    @@SunnyValleyStudio, thank you for your response

  • @four_corner_days
    @four_corner_days8 ай бұрын

    I'm trying this from scratch, but my cell indicator renders below the grass plane while the mouse indicator is correctly rendering above the plane. what could be causing this?

  • @SunnyValleyStudio

    @SunnyValleyStudio

    8 ай бұрын

    I think we have set in a script or as a component variable an "offset" for the indicator. Check the "PreviewSystem" script if we do something like "+new VEctor3(0, someValuse, 0);" when moving the indicator.

  • @HollowGameStudio

    @HollowGameStudio

    2 ай бұрын

    I'm not sure what "PreviewSystem" script Peter is talking about in his comment here, but I found an offset solution that worked for me, as I had this same issue. For some reason I had to set my yOffset to ~0.8 to get the cell indicator high enough to stop z axis fighting. Instead of cellIndicator.transform.position = grid.CellToWorld(gridPosition); I used Vector3 cellIndicatorPosition = grid.CellToWorld(gridPosition); cellIndicatorPosition.y += yOffset; cellIndicator.transform.position = cellIndicatorPosition;

  • @Aushin510
    @Aushin5104 ай бұрын

    Hello, I am having issues with the grid being unaligned and unaffected by any changes to dragging the GridParent around. I am using the Voxel Generator tutorial you made and trying to implement this building grid system in a 3D world. I tried to follow along perfectly (swapping the floor grid indicator for a 3D visual model) but the closest i ever got to a functional (somewhat buggy) 3D grid is this: private void Update() { Vector3 mousePosition = inputManager.GetSelectedMapPosition(); Vector3 gridPosition = new Vector3(Mathf.Round(mousePosition.x), Mathf.Round(mousePosition.y), Mathf.Round(mousePosition.z)); mouseIndicator.transform.position = mousePosition; cellIndicator.transform.position = gridPosition; } With the GridParent Transformed to -.5 on XYZ. Depending on the face of the voxel, it either works correctly or places the grid cursor in the air beside the target block. Any help to my confusion is appreciated!

  • @SunnyValleyStudio

    @SunnyValleyStudio

    4 ай бұрын

    I am not sure but it might be but remember that the Grid component has center points in the bottom-left corner (at least in 2D). Maybe it is a matter of math - that in the voxel generator the center point is in the middle of the voxel. Maybe just adding an offset of -.5 to x and z by default would fix that? The error sounds like a floating point issue where since it it is on the edge of 2 grid tiles it sometimes works and sometimes doesn't, Still might be some more complex problem.

  • @PiFsc2
    @PiFsc29 ай бұрын

    Is there a tutorial to do this in a 2D based game?

  • @SunnyValleyStudio

    @SunnyValleyStudio

    9 ай бұрын

    Sorry not yet 🙂

  • @Robin-xk1pp
    @Robin-xk1pp5 ай бұрын

    How do i change the width of that white part of the Coursor Indicator.

  • @SunnyValleyStudio

    @SunnyValleyStudio

    5 ай бұрын

    As far as I recall we have used a simple quad with a texture to create preview system. You can modify the texture or create the outline using a shader to be able to smoothly modify how it looks.

  • @Sussy_Boy625
    @Sussy_Boy6252 ай бұрын

    would this be able to keep track of what has been placed down?

  • @SunnyValleyStudio

    @SunnyValleyStudio

    2 ай бұрын

    In the tutorial we use "GridData" object to store placed objects and their position. You should be able to easily expend this data or use it to ex "block placement of more than 3 chairs" (so to condition placement based on already placed object). I hope it answers your question!

  • @gudfurt8464
    @gudfurt84642 ай бұрын

    I'd like to do something similar in 2d but I'm having some trouble with the input manager. The z index of the circle I'm using as a mouse indicator is at -6.58 even though my near clipping on the camera is set to 0 (started with 0.001) and it's not following the mouse position either (based on inspector values). Any ideas why and what I could do to fix it?

  • @SunnyValleyStudio

    @SunnyValleyStudio

    2 ай бұрын

    In 2D you actually don't need the Camera Raycast. You would use "Camera.main.ScreenToWorldPoint(Input.mousePosition);" Next you would use that to move your Image (since in 2d we don't use spheres 🙂 unless you know what you are doing) and set it as spheres x and y position. Hope it makes sense! If you are using the new input system you just need to get the mosuPosition from that 🙂

  • @gudfurt8464

    @gudfurt8464

    2 ай бұрын

    Thanks for the response! I tried it without the raycast and it worked out perfectly

  • @ambiepuur1
    @ambiepuur1 Жыл бұрын

    Thanks for this tutorial. Unfortunately I already got stuck at the beginning. I followed every step you took with making the script and set everything where it needs to be, but when I got to 'testing getting mouse position' and click on play, the mouse won't move in the game. It's like it's not seeing the Sphere mouse? Do you have any idea why this is?

  • @SunnyValleyStudio

    @SunnyValleyStudio

    Жыл бұрын

    Check if the Raycast detects your plane. Remember that we use a LayerMask to limit the mouse position detection to the grass plane so the sphere will only move if the raycast detects the grass plane. Easiest way si to Debug.Log(position) inside the hit.collider != null check. I hope it helps!

  • @ambiepuur1

    @ambiepuur1

    Жыл бұрын

    @@SunnyValleyStudio Thank you for the reply! I was searching and searching for what the problem was and I also thought it had something to do with the layerMask. I just found out I typed my mousePos to y and not z. That was the whole problem! Anyway it’s fixed now. Thanks again, I enjoy your tutorials and learn a lot :)

  • @Hrev23.
    @Hrev23.8 ай бұрын

    its not letting me put the zip file into unity, every time I do it says I need to install a new version of unity.

  • @SunnyValleyStudio

    @SunnyValleyStudio

    8 ай бұрын

    The ZIP contains a full project that you have to put inside a new folder on your machine. Next you should be able to open Unity HUB and use the "Add" button. The project I think was created in Unity 2022 so you can use any newer version of 2022 and select something like "convert to" or "open with" and the version you already have. Just confirm any open up window and it should open without an issue.

  • @Hrev23.

    @Hrev23.

    8 ай бұрын

    @@SunnyValleyStudio I'm using 2023 so that might be the problem...

  • @Hrev23.

    @Hrev23.

    8 ай бұрын

    @@SunnyValleyStudiohow do you make the Cursor Indicator? I want to make it from scratch

  • @dynogamergurl
    @dynogamergurlАй бұрын

    does this system work with controllers too?

  • @SunnyValleyStudio

    @SunnyValleyStudio

    Ай бұрын

    If you are using the new input system you could use the controller as well 👍

  • @bleedingflower6078
    @bleedingflower6078Ай бұрын

    I have been having this issue where on one side of the plane the grid snaps all the way to the edge and on the other side it only snaps one early. This makes it so on one side it goes outside of the plane. I have been trying to offset things like crazy. The grid, the plane, the gridparent. I even tested with the sphere as grid indicator and still it indicates that it reaches the edge of the plane on one side but not on the other side. I also have tried scaling but just no change works. I am completely lost on why my grid is completely incorrect.

  • @SunnyValleyStudio

    @SunnyValleyStudio

    Ай бұрын

    So remember how we convert the world position to grid position? Check using Debug.log what is the world position and what the grid position is. It might be that the grid has an offset and when you reach one of the edges the position is Ceiled (rounded up) ? Also remember that we have the grid plane and the ground plane (for simplicity of the setup). The problem might be that one is smaller than the other and when detecting positions on the edge there is actually no collider so the raycast is NULL and the returned position is from the previous row / column. This actually happened to me so maybe that is also an issue in your case?

  • @bleedingflower6078

    @bleedingflower6078

    Ай бұрын

    @@SunnyValleyStudio thank you but I already figured it out. I noticed that it qas working correctly however by default it took the bottem left corner of the grid right on the crossing point. So all I had to do was add an offset in code of 0.5f X and 0.5f Z that put it in the center of the square and fixed it. Before that I was trying to do the offset in unity but ofcoarse that gets reset by the code. But thank you for your response I deeply appreciate the efford you put un to help everyone.

  • @coding_game
    @coding_game11 ай бұрын

    sir cell indecator not working And download the assets from said?

  • @SunnyValleyStudio

    @SunnyValleyStudio

    11 ай бұрын

    Hey! You can check the code here (as I suspect it might be a matter of some missing line of code) github.com/SunnyValleyStudio/Grid-Placement-System-Unity-2022/commit/10d004fefbbac0dcbea0022a53b4ce3ba9c6da89 Also make sure to set the LayerMask of the cell indicator to something other than default as in the code we want to be detecting the ground. I mention it at 5:25 I hope it helps!

  • @user-iv3mg5yn2w
    @user-iv3mg5yn2w4 ай бұрын

    I like cheese burger and your lesson tastes very cheese burger.

  • @SunnyValleyStudio

    @SunnyValleyStudio

    3 ай бұрын

    That is the most creative comment that I had on the channel 😄

  • @redinternet9893
    @redinternet9893 Жыл бұрын

    Does this apply to uneven ground?

  • @SunnyValleyStudio

    @SunnyValleyStudio

    Жыл бұрын

    Well usually the grid is flat (even if the space includes a mountain it should not take more space than another cell in your grid) - so unless you want an irregular grid the only problem is placing the objects or drawing the grid in accordance with the vertices of the mesh. I am not really sure how our shader would work - I assume that it would handle it. In that case all you would need is to adjust the placement position so that the object aligns with the ground. I hope it helps somehow. I haven't tested this system with an uneven ground (like in civilization series) *for an irregular grid you would need a custom grid script

  • @Robin-xk1pp
    @Robin-xk1ppАй бұрын

    is it normal that getting the mouse postion takes away so much fps? Because this makes me worried about the performance of my game. I cannot work efficiently if i dont solve this issue or find out that it is normal.

  • @SunnyValleyStudio

    @SunnyValleyStudio

    Ай бұрын

    No at my end it works great. Maybe for some reason you have added multiple raycasts / multiple scripts that do the raycast to the same GameObject ?

  • @steelman6403
    @steelman64036 күн бұрын

    Would this work in a first person system

  • @SunnyValleyStudio

    @SunnyValleyStudio

    6 күн бұрын

    Yes. You could still shoot a raycast from the camera of the player just in the forward direction. The use of Grid component should work for any kind of grid placement system - it is reusable. I think that you would have to consider creating multiple grids in case your world is very big. So you might need to make a few changes to the project 👍

  • @Rexu3030
    @Rexu303011 ай бұрын

    I creating project in 3d URP but i haven't this folders and scenes as you.

  • @Rexu3030

    @Rexu3030

    11 ай бұрын

    Pls help!

  • @SunnyValleyStudio

    @SunnyValleyStudio

    11 ай бұрын

    It is best to download the full project (ZIP filed), unpack it to a separate folder and use unity Hub "open" on it to add open the same project as I have. The scene should be in the "Scenes" folder. Sorry for not explaining it better!

  • @Rexu3030

    @Rexu3030

    11 ай бұрын

    @@SunnyValleyStudio thanks

  • @prasannakuppu3165
    @prasannakuppu316511 ай бұрын

    Can we create this grid system at runtime?

  • @SunnyValleyStudio

    @SunnyValleyStudio

    11 ай бұрын

    Yes. Grid component just do the calculations for you. It doesn't creates anything scene relevant (well it needs to be added on a gameobject so it knows its origin position since it calculates the grid coordinates taking into account the position where it is placed in the world space).

  • @lukgoolaerts3085
    @lukgoolaerts30855 ай бұрын

    Somehow when i follow this tutorial, the sphere (mousepointer) starts where the mouse is, but then flies straight to the camera, and i can't figure out why. Strange

  • @SunnyValleyStudio

    @SunnyValleyStudio

    5 ай бұрын

    Have you set the Spheres layer to something other than "default" ? I might have gone over this too fast. Basically if sphere has the same layer as the detection layer the sphere will be gradually moving towards the detected point - which is on the surface of the sphere. This will cause it to fly towards the camera. Sorry for not explaining it better in the video!

  • @lukgoolaerts3085

    @lukgoolaerts3085

    5 ай бұрын

    @@SunnyValleyStudio Yes, problem with the layers. instead in changing the layer i added it so, I had the problem you describe above. Thanks for answering

  • @Telikal
    @Telikal11 ай бұрын

    How do I impor tthe grid placement system I cant figure it out.

  • @SunnyValleyStudio

    @SunnyValleyStudio

    11 ай бұрын

    The best way is to download the ZIP archive, unpack it to a separate folder and use "Open" button in the unity Hub to open it as a new project. If you want to import a package to an existing project here is Unity manual about importing docs.unity3d.com/560/Documentation/Manual/AssetPackages.html

  • @aciloaicilo2926
    @aciloaicilo2926 Жыл бұрын

    why we have to change z mouse position value to nearClipPlane value? i tried this script without this code, it works the same (i think).

  • @aciloaicilo2926

    @aciloaicilo2926

    Жыл бұрын

    i found the same code in unity docs. but i still dont understand why we need this. :(

  • @SunnyValleyStudio

    @SunnyValleyStudio

    Жыл бұрын

    We do that because we are using a perspective camera. Take a look at Camera View Frustum docs.unity3d.com/Manual/UnderstandingFrustum.html If we don't set the z value the the calculated value will be based on the distance closer to the camera on a much saller plane of the frustum. This will mean that in our near clip plane your mouse movement is tiny compared to the plane but closer tot he camera you have moved very far. This will result in your objects moving very far compared to your visible mouse movement. Now in our project we wanted the camera to be almost orthographic so the difference might be not that noticeable. I hope it answers your question.

  • @aciloaicilo2926

    @aciloaicilo2926

    Жыл бұрын

    @@SunnyValleyStudio thanks

  • @Robin-xk1pp
    @Robin-xk1pp6 ай бұрын

    How can i make a circular grid? The cells have to be a square and they need to form a circle.

  • @SunnyValleyStudio

    @SunnyValleyStudio

    6 ай бұрын

    You should consider it in terms of painting pixel art in Aseprite (or paint or any software). There you have a "brush" which defines a selection shape. All you need is to find or figure out an algorithm to select all the grid cells using some radius value from a specified position. Not sure if that is what you mean. In terms of the shader I don't think it would be that easy to create it. I think the easiest solution is to generate a mesh / or create it in Blender that is of the shape of your circle and put the shader on it so that it only shows the "circular" grid made of squares. I hope it makes sense!

  • @Nar1ndaa
    @Nar1ndaa5 ай бұрын

    Why we need Vector3Int gridPosition = grid.WorldToCell(mousePosition); cellIndicator.transform.position = grid.CellToWorld(gridPosition); ? Why not Vector3Int gridPosition = grid.WorldToCell(mousePosition); cellIndicator.transform.position = gridPosition;

  • @SunnyValleyStudio

    @SunnyValleyStudio

    5 ай бұрын

    I think this is because your cell position is relative to the grid object. If we move the object the cell position will not be the same as world position. The cell indicator on the other hand is placed relative to the world space. I might be wrong here but that was my reasoning 🙂

  • @Nar1ndaa

    @Nar1ndaa

    5 ай бұрын

    @SunnyValleyStudio thanks for answering! This part is really hard to undersand for me

  • @thegamerguyplays5275

    @thegamerguyplays5275

    3 ай бұрын

    @@SunnyValleyStudio Hi SunnyValleyStudio, could you simplify this more? what is the purpose of celltoworld? I still don't quite understand what its for. I'm quite new to programming so i'm trying to learn the fundamentals of each piece of code. I've been wracking my brain for hours trying to figure out what this does exactly 😅

  • @wisdomkhan
    @wisdomkhan6 ай бұрын

    My cell indicator is not matching with unity grid.

  • @SunnyValleyStudio

    @SunnyValleyStudio

    6 ай бұрын

    I recall that since the Tilemap tile has its center in "bottom-left" corner we have applied an offset either to the prefab or to the placement of the cell indicator of (0.5f, 0f, 0.5f). Maybe that is the problem?

  • @Haffels
    @Haffels19 күн бұрын

    does this work in 2d

  • @SunnyValleyStudio

    @SunnyValleyStudio

    17 күн бұрын

    In 2D you can just use Tilemap component since it is based on Grid component!

  • @Rexu3030
    @Rexu303011 ай бұрын

    Is this working in 2D game?

  • @SunnyValleyStudio

    @SunnyValleyStudio

    11 ай бұрын

    Hey! Yes. In unity most of the objects works with 3D and 2D systems. In 2D Grid component is used in Tilemaps so you can ask Tilemap for grid coordinates directly ex docs.unity3d.com/ScriptReference/Tilemaps.Tilemap.GetCellCenterWorld.html. You can still ask Grid as this is what answers your method call at the end.

  • @tomasa9690
    @tomasa969011 ай бұрын

    You shared used assets but the link goes to nowhere, it just opens the whole website

  • @SunnyValleyStudio

    @SunnyValleyStudio

    11 ай бұрын

    Sorry about that! kenney.nl/assets/furniture-kit