Hi @Kiwasi ,
I had a look at your project. Overall, the way you’ve used Panda is simple and straight forward. I like this style.
Looking at the way you build the BT controlling the player firing, it seems (I’m not sure) there is confusion about how the while node works:
tree "Shoot"
Sequence
Wait 1.5
While PlayerPressShoot
PlayerShoot
And this is the definition of PlayerPressShoot:
[Task]
void PlayerPressShoot ()
{
if (Input.GetButton("Fire1"))
Task.current.Succeed();
}
The PlayerPressShoot task runs and succeeds when the player press the “Fire1” button, and it never fails.
The while node is used to run a task under an assumption, if the assumption fails the task is not ticked and the while node fails. You can think of it as a guard. However, the PlayerPressShoot task never fails, so guarding the PlayerShoot task is not necessary.
I guess you wanted to do something as follow:
First define a task that tells whether the player is pressing the fire button or not:
[Task]
void IsFireButtonPressed()
{
Task.current.Complete(Input.GetButton("Fire1"));
}
This task completes immediately. it succeeds if the “Fire1” is pressed, and fails otherwise.
Then the behaviour tree would be:
tree "Shoot"
Sequence
IsFireButtonPressed
PlayerShoot
Wait 1.5
So, sequences can be used to implement conditionals. Here the sequence fails if the fire button is not pressed, leaving the remaining task non-executed. In other words, “PlayerShoot” and “Wait 1.5” are executed only if “IsFireButtonPressed” succeeds.
I really like the way you’ve implemented the GameController:
tree "Root"
Sequence
FreezeGame
Wait 120
StartGame
Race
GameWon
GameLost
FreezeGame
Wait 120
RestartLevel
Particularly, the way you’ve used the race node to decide how the game ends. I would never have thought to use the race node in this situation :).
I would like add a point about the character case in script. The language keywords (tree, sequence, fallback, …) are case insensitive. So, for example, it’s up to to you if you want to write sequence, Sequence, SEQUENCE or even SeQuenCE. However task name are case sensitive: the task name in a BT script has to be the exact same name as the C# method.
This property can be used for defining a convention to distinct between the language keywords and the tasks. I like to use only small case for the keywords and CamelCase for the task. When the task has some variable, I separate it with an underscore (for example: SetDestination_EnemyPosition). But convention is a matter of taste, so it’s up to you and your team to define one.