State Machine Setup for 2D Platformer Character ~ Godot 4 GameDev Tutorial

Published: 01 April 2023
on channel: Chris' Tutorials
113,485
2.4k

Break down a complex character into more managable states that run selective code and can transition into each other while controlling animations through AnimationTree and the playback travel function. This is one example of how you can structure a character for a platformer character to scale up to having many animations and different rules for how the character moves around your Godot 4 game world.

Use Part 1 End Project (below) as the Starting Point for This Tutorial to Follow Along

Download Project ➣ https://ko-fi.com/post/Godot-4--Platf...
Also on Patreon ➣   / godot-4-quick-80723131  
Art Pack Used https://anokolisa.itch.io/sidescrolle...
Part 1 ➣    • 2D Platformer Quick Start Guide ~ God...  
Part 2 ➣    • 2D Platformer Attacks and Enemy Setup...  

➣ Downloadable Assets, Video Courses, and Other Places to Follow Me
https://linktr.ee/ChrisTutorials
https://ko-fi.com/christutorials
https://chris-tutorials.itch.io/

00:00:00 - What to Expect
00:01:29 - Starting Point
00:03:12 - Download in Description
00:03:25 - Add Nodes (Sprite, AnimationTree, AnimationPlayer)
00:04:26 - Idle Animation in Animation Player
00:09:10 - Run Animation
00:10:56 - Move BlendSpace1D
00:13:16 - Setting Animation Parameters
00:17:20 - Facing Direction
00:18:04 - Removing Animated Sprite References in Player script
00:19:48 - Setup State Machine
00:20:54 - Setting Up State Scripts
00:23:31 - Get States in State Machine
00:25:47 - State Can Move
00:29:58 - Jump from Ground State
00:35:12 - Change from Ground to Air State
00:37:15 - State OnEnter and OnExit
00:40:04 - State Debug Label
00:41:49 - Exit Air State to Ground State
00:44:12 - Double Jump from Air State
00:47:48 - Reducing Gravity for More Floaty Characters
00:48:19 - Jump Animations in Animation Player
00:51:46 - Animation Tree Setup
00:54:12 - Travel Tree through Playback
00:57:49 - Landing State
01:01:43 - Switch to Air when Not on Floor
01:02:37 - Player Script Cleanup
01:04:02 - Animation Position Offset due to Sprite Centering
01:05:37 - Wrapup


Watch video State Machine Setup for 2D Platformer Character ~ Godot 4 GameDev Tutorial online without registration, duration hours minute second in high quality. This video was added by user Chris' Tutorials 01 April 2023, don't forget to share it with your friends and acquaintances, it has been viewed on our site 113,485 once and liked it 2.4 thousand people.