ioxu / key

Key, a game made with the Godot Engine 4.
MIT License
6 stars 1 forks source link

enemies move faster at lower physics fps #50

Closed ioxu closed 1 year ago

ioxu commented 1 year ago

Recently lowered project physics/common/physics_ticks_per_second from 120 to 60 fps, and now enemies move too fast. Frame delta is not integrated correctly somewhere in enemy _physics_process. Enemy FSM is involved - fsm base class passes delta to each state from its own _physics_process.

ioxu commented 1 year ago

Can't work it out.

movement_speed is set in enemy finite state machine actions, multiplied by delta eg: https://github.com/ioxu/key/blob/d1c8bbb59f8b4a149720f69a470137f88b82904b/data/enemies/Enemy.gd#L419

delta is passed to fsm states in statemachine.gd https://github.com/ioxu/key/blob/d1c8bbb59f8b4a149720f69a470137f88b82904b/data/statemachine/statemachine.gd#L14-L19

... there must be an un-delta'd term in enemy._physics_process()

ioxu commented 1 year ago

nb to change physics ticks per second:

Engine.set_physics_ticks_per_second(value)
ioxu commented 1 year ago

... I completely forgot that move_and_slide() applies delta itself: https://docs.godotengine.org/en/4.0/tutorials/physics/physics_introduction.html#move-and-slide

ioxu commented 1 year ago
ioxu commented 1 year ago
ioxu commented 1 year ago

I think that's got it. 🚀