I coded a 2D player controller in 2 LINES! (Godot 4)
ฝัง
- เผยแพร่เมื่อ 20 ต.ค. 2024
- #gamedev #challenge #godot
🚀 Support me on Patreon: / minapecheux
In Godot 4, it's easy to make a player controller script, both for 2D and 3D. But... how much could we actually shrink it down? Can we implement this in just 2 lines of code? (Spoiler: yup!)
Time for a little Godot/GDScript game dev challenge!
================
Music by: Bensound.com/free-music-for-videos
License code: 2QYXGHHKBXHYVPZJ
Love how you focus on concept and not just raw code.
Thanks, I'm glad you liked the approach! :)
Loved it you're sooo talented ❤❤🎉😌😌
Haha thanks :)
Loved the video. Very simple. I was wondering where you got the assets from, since I can't find them at Kenney's or Lousberg's.
Thanks, glad you liked it! I actually made those myself :) (if you're curious, those were part of my latest "mini-solo-jam" project which I detailed in this devlog video: th-cam.com/video/NDgQlPYqvak/w-d-xo.html)
(I just realised I forgot to remove the asset links from the desc, those were copied from another video - thanks for helping me see it!)
Cheers!
@@minapecheux I actually saw that video after this one! Always have been a fan of Paper Cutout style sprites, so I loved how it looked. Good job!
@@softbread1728 Glad you liked the other video, thanks a lot for your kind comment :)
I just started learning Godot and programming. And I have a question. Will shortening the code this way improve performance?
Heya! Honestly - not in all generality, but here I think there shouldn't be any impact ;)
I'm mostly removing spaces or new lines, and the only real change in terms of logic is calling move_and_collide() instead of move_and_slide(). And if you look at the Godot engine's open code on Github (github.com/godotengine/godot/blob/master/scene/2d/physics/character_body_2d.cpp#L112), you'll notice that the move_and_slide() logic in fact calls move_and_collide()! So we're not changing a lot here, we're even simplifying things a little.
(Plus, since we're not declaring a variable for the input direction computation anymore, we're saving a little bit of memory as well.)
However, keep in mind that this is just true in this case. In other cases, you might "shorten the code" in less efficient ways :)
Hope it helps,
cheers!
t'es francaise? chouette video!
Yup, tout à fait :) Merci beaucoup, ravie que ça t'ait plu !!
Nice!
We can make the entire game in a single unreadable line that will make no difference to the compiler because we are the chad 😎
That challenge was definitely not best practices but it works 😅
Can you make a character select tutorial in godot
I like the idea! You're thinking more of a character class/hero selection screen, or a rts-like unit selection? 🤔
Thanks for the suggestion anyways!
Cheers :)
How to have the input method player controller for creating a mobile game? May I request a tutorial from you?
Heya! That's definitely a great idea! I'll admit I'm a bit less versed in mobile games so I don't think of topics related to this platform, but it's absolutely worth exploring - I'll add it to my to-do list, thanks a lot for the suggestion :)
E F F I C I E N C Y😂
Strange accent + speaking fast = not a very understandable result.
Heya - I'm sorry you couldn't enjoy the video. If you want, there are English/French subtitles on this one.
Hope it helps :)
Cheers!