2D Movement in Godot 4 using TileMap

preview_player
Показать описание

In this video we take a look at how to implement 2D movement based on TileMap cells in combination with custom data layers and collision shapes.
Рекомендации по теме
Комментарии
Автор

In order to not have the single frame stutter in-between movements you should put line 17 of the player script between the two if statements on line 12. This will prevent an early return and not moving on a single frame once a target has been reached, it should result in smoother camera movement too.

RetroBright
Автор

Thank you SO MUCH. Learning Godot after years of Unity, this tutorial gave me exactly the kind of basics I needed to get going. Clear, concise, no extra fluff. Perfection.

kamest
Автор

As a Godot and coding newbie, I couldn't have asked for a better tutorial on this topic. Introduced me to new nodes, and showed a clear example of how to work with tilemaps in scripts. Using the RayCast2D to control where the player can and can't move is perfect, as it essentially makes the collision shapes function like they do in traditional 2D movement, and made things super easy to implement in a little learning project I have going.

Going to be watching your other videos on grid-based movement, and I'm looking forward to see what you make in the future. Many, many thanks for this tutorial!

ItsUnderMotion
Автор

I really appreciate how you explain why you do things, what a particular phrase does, and make reference to little things like something being an object etc. Just helps me absorb what is happening since I'm still learning GDScript

SamuelHaak
Автор

One of the best tutorials I've come across on YouTube.

1. Briefs reminders of the uses of certain functions and nodes while also having a good pace and demonstrating why you use it.
2. Covers gameplay aspects both for tactics games (what I intend) and for action-RPG.
3. It covered some less-common (in tutorials) functions, but more efficient and it also helped me learn to debug better and have a better understanding of the engine as two or three things didn't go as planned, but managed to fix them using my knowledge from the video.
4. Excellent voice with great commentary and useful tools.

Thanks for the tutorial!

Animefan
Автор

I commented in the same thing in a similar video:
If your videos are focused on code mostly, consider zooming in your font size or focus your recorder on that editor part.
It's much more accessible, as not everyone has a matching 4k Display at all time or a 20/20 vision to read that tiny font.
Just a tip.

yt_n-cde-r
Автор

Thanks a lot for this video, straight to the point, easy to understand. I really appreciate you going step by step and taking time to add those logs before proceeding so we could verify what was going on. Incidently, I had a bug early on with my implementation because I moved the sprite and not the player node so all the calculations were off until I realized my mistake.

mercantilistic
Автор

This is the best source of information I've found about Godot so far, it encapsulates everything I've been trying and failing to learn for the last few hours on the forums and documentation.

StrawbellyASMR
Автор

Excellent video. One of the better Godot tutorials I've watched. Clear and concise. Hope to see more beginner mechanics for different game types.

introyvert
Автор

Amazing tutorial. Quick explanation and a really solid implementation.

Not sure if this is a better solution to yours, but I used tweens to move the player. This gives me more control over the animation via the set_trans() function. Here's the code if anybody is interested. Remove the _physics_process() function and copy this code at the end of the move() function.

# Move player
is_moving = true
global_position =
sprite_2d.global_position =

var tween = create_tween()
tween.tween_property(sprite_2d, "global_position", global_position,
await tween.finished

is_moving = false

UitzUitz
Автор

This was extremely helpful. Got a little confused part way through and had to rewatch, but I went from never having coded anything to smoothly moving my sprite on the tilemap grid. Thanks!!

kordlesskure
Автор

Late to the party but this is incredibly useful thank you, it's remarkable how many tutorials simply gloss over all the shiny new features like custom data layers and don't even show code samples properly. Classic problem of not very helpful short form click-bait making it's way to the top of search results and anything with real information being shoved down.

lethn
Автор

Such helpful explanation, plus your code are so clean to read and understand

nahruz.w
Автор

Thank you so much!!! I was looking for a tutorial covering grid like movement and this was perfect!

cthetrickshooter
Автор

Thank you for this, excellent stuff. I'm following along in C# but this is still really helpful, I'm mostly clueless at game dev so wasn't really sure how to approach doing this and you've saved the day.

adam
Автор

Very nice tutorial! I checked out many different approaches for Tilemap based movement and i like this one best for what i'm working on! Thank you!

jobibonobi
Автор

Amazing tutorial. I'm new to godot, this is exactly what I needed, and I learned about some more functions I didn't know about yet. Thank you very much~

Lumayoshi
Автор

Nice and clean tutorial. Thanks for saying why you did what you did, it's very helpful!

Slipy
Автор

Thanks for the great tutorial. I got the "Cannot call method 'get_custom_data' on a null value" error when moving up and left. I was able to fix it by changing the "Player" and "Sprite2D" (knight image) Node2d > Transform > Position x and y in the Inspector. In my case, it was fixed after changing "Player" to 24, 40 and "Sprite2D" to 0, 0.

plutoerebus
Автор

Very, very well done! Took me a few times to get it, but who says you can't teach an old dog new trick!

victorbied