Action System for Player and Enemies

Godot Version

4.5.1

Question

Hey all, so I seem to be suffering from some decision paralysis about how I should handle the creation of my player and enemies characters.

I would like a system where the player and enemies can perform a variety of actions. Such actions could be, moving, casting a fire ball spell, attacking with a heavy weapon or teleporting to a random spot in the room. I don’t want these actions to be tied to any specific character rather I want to assign any action to any character to hopefully create a unique move set for the character.

What do you think the best implementations for something like this would be? Are there any specific programming patterns that I should look into? If you have dealt with something like this before, what was your approach?

I’m currently making each action its own resource that can be dragged on to the player or enemy. The player or enemy would then just run some function called do_action1() and then call the action() function in the resource.

Again, not sure what the best approach would be but I am curious to see what you all have to say.

Thanks!

Defs worth looking into command patterns.

You’ll find this book linked a lot.

As for your dilemma, I get it. Its really hard to settle on a choice that might not be the best solution. i think it’s important to remember that it doesn’t need to be perfect and at the end of the day, you should aim to start and finish something.

I have a command pattern system setup where I have a weapon resource script that holds stats and export variables that I can put my model meshes and other effects into. Its not perfect but I have the main weapon scene script setup with functions for shooting and weapon swapping between the resources. Whenever I swap weapons it runs a function to load all the new variables of the other weapon.

I’ve also created some bullet types and I’ve coded them all a bit differently to make each ammo type feel a bit different too. Mainly just Different movement patterns at this point. The bullets also all have hot boxes so that’s used for detecting that collision.

It’s not perfect but right now, it works for my prototypes and allows me to continue learning.

So yeah, look into command patterns and just make something :slight_smile:

Yeah Ive seen this book mentioned everywhere and have looked it over a little bit. honestly I should just buy the thing at this point, haha.

I will try looking at the command pattern and see what I can do with it. Thanks!

No probs friend!

I could be wrong but I think this video uses the command pattern in a cool way. Either way it’s a useful video for making a modular weapon system :slight_smile: