#Gravity is not applying to the Boss Enemy, when it’s in a certain state

1 messages · Page 1 of 1 (latest)

solar heath
#

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.

dense wadi
#

Keep in mind you're enabling and disabling physics twice per attempt, one call from the super class and another in the given state.

It could be causing issues when you try to disable it mid-calculation.

The order of operations from the FSM is a bit odd too, you first enter() a state and then exit() the old one. This is not only unintuitive (you should only be on one state at any given time) but it means you're first entering (physics enabled) and then exiting the old one (physics disabled)

#

And the last change is the one that remains.

weak rose
#

physics_process is being disabled when entering the _dying state.

dense wadi
#

Yes, but as i said, whatever happens upon entering is instantly overwritten by exiting the previous state.

#

Since both change the state of physics processing and exiting happens last, that's the one that decides the final state of processing.

weak rose
#

I agree

#

The code is not intuitive, there are many changes being made by external elements, which can cause conflicts like this. According to him, he is making a tutorial, but I would strongly recommend adopting another alternative to deal with this type of requests. As the project grows it tends to become more complex and confusing.

dense wadi
#

oh, i tought you where OP lol
my bad.

weak rose
solar heath
#

Resolved this issue.
Resolution: Scrapped the entire thing and started to use the State Charts plugin with the help of the below tutorial. Worked like a charm.
https://youtu.be/E9h9VnbPGuw?si=57879ObPVyBSXyrd

Hello Godotneers! With the Godot State Charts library you can easily create complex behaviour in your game with very little code. In this video I'm giving you an overview on the features and how to use them.

Links:

▶ Play video
dense wadi
# weak rose what?

That you where the one who made the post. So i misunderstood your message.