+1 vote

im currently making a flexible template class for variable of characters and an ai class that takes a character as a parameter and applies default ai on that
so as an example i store the function that handles player movement on a variable as a funcref and when i pass this character to ai class it reroutes the movement function to its own and player cant control the character anymore

asked Aug 27, 2019 in Engine by chastifole (13 points)

So you're trying to design your system of movement such that the player can sometimes move the character, and at other times, an AI unit can move the character?

1 Answer

+1 vote

There are couple of ways to do it. Simplest would be to make one boolean like player_controlled and simply check if it's true or not. If true, then make your whole routine of checking for inputs and other stuff, if false, then skip this and run your AI functions instead.

You could also attach different script to a node, depending on whether it should be player controlled or not. One script would be for the player, one for AI.

Which implementation would be optimal depends on your specific game.

I've done something similar, where I switch AI behavior this way - I got one variable, that takes whole script through one of many different paths, to create more passive or aggressive AI, change AI goal between killing player, attacking NPC, protecting important location ect.

answered Aug 29, 2019 by Skipperro (125 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.