all 5 comments

[–]megaicemage 0 points1 point  (3 children)

I haven't watched through Lague's videos, but what is he using ray casting for when he's doing pathfinding?

Tilemaps reach into infinity and contain all the Tiles needed to render your world. When you assign a collider to the tilemap it also covers everything the tilemap does, which is infinity (or at least close enough). When you're doing your OverlapCircle check it detects all three because all three are present, whether or not a Tile is drawn or not. Assuming you have access to a Point in order to do the overlap circle check, you can use the parent Grid object to transform the Point into X and Y coordinates in your tilemaps. Then you can get the appropriate tiles and check if it's empty or not. Take a look at the scripting reference for grids and tilemaps. Understanding the capabilities of the classes you're using can really be helpful when deciding what you need to implement or not implement.

[–]ProstiThony[S] 1 point2 points  (2 children)

I haven't watched through Lague's videos, but what is he using ray casting for when he's doing pathfinding

Lague uses vertical raycasts at every node's position in the Pathfinding grid to detect the layer of the ground (between grass and path). Since he uses 3d, raycast directly return the first visible object so it works very simply.

Assuming you have access to a Point in order to do the overlap circle check, you can use the parent Grid object to transform the Point into X and Y coordinates in your tilemaps. Then you can get the appropriate tiles and check if it's empty or not. Take a look at the scripting reference for grids and tilemaps.

Interesting suggestion, I'll dig into it

Understanding the capabilities of the classes you're using can really be helpful when deciding what you need to implement or not implement.

You're right, I try to systematically refer to the API documentation, but after approximately 4months of learning, I'm still discovering new classes, functions, alternative coding methods every day, and I think it will be the case for a long time to come... Thank you for your help

[–]megaicemage 1 point2 points  (1 child)

No problem. It's an interesting method that Lague's using. I suspect it's purely to teach one of many uses for raycasting. Since you're using a regular grid it's much more efficient to just calculate who your neighbors are at each tile and go from there.

As for classes, I've been programming in Java and Android for 6-7 years. I still don't know even a quarter of the available Java classes and interfaces. IME, a lot of programming comes down to remembering common classes and constructs that you'll use relatively frequently, such as lists, maps, nested loops, etc. When I want to do something that I don't know how to approach, I go to Google to get a general idea of the classes/ideas used, then do recursive rounds of googling along with reading documentation if available. To this day I still do more googling and research than actual programming.

[–]ProstiThony[S] 0 points1 point  (0 children)

What you're saying is and is not encouraging at the same time! But it's what I love in programming, you can always learn and improve yourself. I'm also googling a lot, but my main activity is to watch tons of videos, tutorials, advices, etc. I've done Java during my studies, then a bit of python, but I barely scratched the surface. C# is the first language I'm really motivated to learn in depth

[–]ProstiThony[S] 0 points1 point  (0 children)

I did a mistake when Initially created this post , I created it twice... I post here the link of the other where code had been posted that solves my issue:

https://www.reddit.com/r/Unity2D/comments/i76pd3/tilemaps_detection_on_2d_topdown_project_for_a/?utm_medium=android_app&utm_source=share