Hello,
I've been following the below tutorial and created a boss enemy for my game.
https://youtu.be/otHfaomtJh0?si=FrU-u5WSTWh_-usr
The boss_enemy uses a Finite State Machine to switch between states.
I made slight modifications to fit my game. (Added gravity, additional states, etc.)
As per the tutorial, the _physics_process is disabled initially. And is enabled on whichever states that require it.
In the tutorial and my original code, _physics_process is enabled only in the "Follow" state. It is disabled in all other states.
Afterward, I introduced 2 new states.
- Death_Fall (_physics_process enabled)
- Death_Collapse
When the boss_enemy dies, the states change in the following order.
<current state> -> Death_Fall (Till is_on_floor == true, has gravity) -> Death-Collapse (No gravity)
The issue I'm facing is as follows.
When moving from a state where _physics_process is disabled (Ex: "RangedAttack" state), the gravity is applied after moving to the "Death_Fall" state without any issue.
But when the current_state is the "Follow" state (where _physics_process is enabled), and when moving to the "Death_Fall" state, the gravity is not applied.
Some code snippets that I thought was necessary are attached.
IMG 01: Boss Enemy main script: _physics_process
IMG 02: Boss Enemy main script: die() function. Called when the enemy is dead and switches to the "Death_Fall" state.
IMG 03: "Follow" script: Extends from "State.gd". Child of the FiniteStateMachine node.
IMG 04: "Death_Fall" script: Extends from "State.gd". Child of the FiniteStateMachine node.
IMG 05: Scene tree of the Boss Enemy node
IMG 06: FiniteStateMachine script: Parent of all State nodes
IMG 07: State.gd script: All scripts of the states extends from this script.
Any help on this would be much appreciated.
Boss fight with Finite State Machine in Godot 4
-
Asset Used -
https://darkpixel-kronovi.itch.io/mecha-golem-free -
Code -
State - https://pastebin.com/Dw3urW9n
FSM - https://pastebin.com/d8c8e4pD
Idle - https://pastebin.com/gURXAcwe
Follow - https://pastebin.com/qwAGqK4A
MeleeAttack - https://pastebin.com/YXy9Ruga
Homing Missile - https://pa...