Script that extends CharacterBody3D built-in script and replace Arrow Keys with WASD

I’m completely new to Godot Engine and GDScript. My approach to game development might be non-standard.

Godot Version

4.3

Question

So I want to extend CharacterBody3D with a new script character_body_3D_input_wasd.gd to allow WASD keyboard movement.

I do not want to modify the original character_body_3D.gd script and keep it original, built-in.

Later if I delete character_body_3D_input_wasd.gd it should restore the original Arrow Keys keyboard movement.

Is this plausible/reasonable in Godot Engine or should I instead directly modify character_body_3D.gd? Could someone provide with working example or the way is done?

Is there a reason you can’t edit the input map?

1 Like

Currently I’m learning and it gets tiring to do this UI all the time for each project.
Dropping a single script that would temporary extend feature and allow you to continue work/do testing on different projects is what seems more right and appealing. But currently I’m stuck and wonder if anyone tried this non-gui way before and could share experience.

You can programmatically add actions via the InputMap class, and also delete them if so desired. It’s a singleton, so if you extend an existing CharacterBody3D with a new script that edits the InputMap in _ready, I think you’ll get exactly what you want.

1 Like

You don’t have to do it manually for each project. Just open project.godot in your current project’s folder, find the section starting with [input] and copy/paste it to project.godot of any other project.