Godot Player Controller Script Generator (GDScript)

Pick a template, set speeds, input action names and options, and get a ready-to-attach Godot 4 GDScript file with typed exported variables. Templates cover a 2D platformer character controller with coyote time and jump buffering, 2D top-down movement, a 3D first-person controller, a simple state machine, a health component with signals and an autoload singleton, and each one lists the nodes it expects.

Step 1 of 3: Template
What should the script do?

How to use it

  1. Choose a template, such as 2D platformer or 3D first-person, then press Next.
  2. Set the speeds, toggles and input action names, or press Reset to defaults, then press Next.
  3. Check the summary on the Review step and press Generate script.
  4. Press Copy code or Download .gd, then follow the Node setup list under the code.
  5. Press Copy Ziva prompt to have Ziva build a playable test scene around the script.

Coyote time and jump buffering in Godot

Coyote time lets the player jump for a short moment after running off a ledge, and a jump buffer remembers a jump press made just before landing. Both forgive inputs that are a few frames early or late, which players read as responsive controls rather than missed jumps. Values around 0.1 seconds are a common starting point; tune them by playing.

In the generated platformer script, a coyote timer is refilled every physics frame while is_on_floor() is true and counts down in the air, and the jump buffer timer is set when the jump action is pressed and counts down every frame. A jump happens when both timers are above zero, then both reset so one press cannot trigger two jumps. The short hop option multiplies upward velocity by jump_cut when jump is released early, giving a lower jump for a tap.

Jump height follows from jump_velocity and gravity: height = jump_velocity squared / (2 x gravity). With the default 2D gravity of 980 pixels per second squared and a jump velocity of 450, that is 202500 / 1960, about 103 pixels. To jump over a 3-tile wall with 32 pixel tiles (96 pixels), you need at least the square root of 2 x 980 x 96, about 434 pixels per second.

How these scripts differ from Godot's built-in templates

Godot's CharacterBody2D Basic Movement template uses constants (SPEED = 300.0, JUMP_VELOCITY = -400.0), the built-in ui_left, ui_right and ui_accept actions and instant acceleration. The generated scripts use @export variables so you can tune speeds in the Inspector while the game runs, your own input action names, and optional acceleration and friction with move_toward().

Gravity comes from get_gravity(), added to CharacterBody2D and CharacterBody3D through PhysicsBody in Godot 4.3. It returns the project's default gravity (Project Settings > Physics > 2D > Default Gravity, 980 by default) plus any Area2D or Area3D gravity overrides, so water or low-gravity zones work without extra code. That is why the scripts need Godot 4.3 or newer.

The top-down script sets motion_mode to MOTION_MODE_FLOATING, which Godot's class reference describes as the mode for games with no notion of floor or ceiling, such as top-down games: every collision counts as a wall and sliding keeps a constant speed.

Using the health component and autoload

The health component is a plain Node you add as a child of any player or enemy. It emits health_changed(current, maximum), damaged(amount), healed(amount) and died, so a health bar, hit flash and death animation can each connect to a signal instead of checking health every frame. With a class_name, the script also shows up in the Create New Node dialog and works as a type hint.

An autoload is a node Godot adds to the root of the scene tree before your main scene, reachable by name from every script. Register the script in Project > Project Settings > Globals > Autoload. Do not give the script a class_name equal to the autoload name: Godot rejects it with the error that the class hides an autoload singleton.

The autoload's save option writes the high score as JSON to user://save.json with FileAccess. Godot guarantees user:// is writable, even in an exported game, while the project folder (res://) is likely read-only once the game ships.

Frequently asked questions

Which Godot version do these scripts work with?
Godot 4.3 and newer. The scripts use Godot 4 syntax such as @export, typed variables and signal.emit(), and the movement templates call get_gravity(), which was added in Godot 4.3. Every template variant was checked with the Godot 4 script parser.
Why does my player not move after adding the script?
The input actions the script reads, such as move_left and jump, must exist in Project Settings > Input Map with keys or buttons assigned. Add them there, or generate them with the Godot Input Map Generator. Also check the script is attached to a CharacterBody2D or CharacterBody3D that has a CollisionShape child.
What is coyote time?
Coyote time is a short grace period after the player walks off a ledge during which they can still jump. It makes platformers feel fair because a jump pressed a few frames late still works.
Can I use the first-person controller with a gamepad?
Movement works with a gamepad as soon as you bind the stick to the movement actions in the Input Map, because the script reads them with Input.get_vector(). Camera look in the template uses mouse motion only; add the right stick by reading two more actions in _physics_process and rotating the same way.
Is the GDScript generator free?
Yes. The scripts are built in your browser from fixed templates, with no account and no AI, and you can use the generated code in any project, commercial or not.
  • Godot Input Map Generator: Godot 4 input actions for keyboard, mouse and gamepad, as an autoload or a project.godot section.
  • Godot Shader Generator: Pick a 2D effect, tune its uniforms with a live preview and download a Godot 4 .gdshader.
  • Godot 3 to 4 Converter: Rule-based GDScript upgrade from Godot 3 to Godot 4, with a line-by-line change list and manual-work warnings.

See all tools