It seems like the physics update is asynchronous to the normal update - that is, there’s no guarantee on the order in which FixedUpdate() and Update() will be called. Sometimes Update() could be called twice before FixedUpdate() is called and vice-versa.
This is a problem when using GetKeyPress() inside of FIxedUpdate(). It doesn’t always respond. Some example code:
class Foo : public Urho3D::LogicComponent {
public:
virtual void Update(float timeStep) override {
if(input_->GetKeyPress(KEY_SPACE))
puts("key pressed in Update()");
}
virtual void FixedUpdate(float timeStep) override {
if(input_->GetKeyPress(KEY_SPACE))
puts("key pressed in FixedUpdate()");
}
};
Output after pressing space a few times:
key pressed in FixedUpdate()
key pressed in Update()
key pressed in FixedUpdate()
key pressed in Update()
key pressed in FixedUpdate()
key pressed in Update()
key pressed in Update()
key pressed in Update()
key pressed in FixedUpdate()
key pressed in Update()
key pressed in Update()
key pressed in FixedUpdate()
key pressed in Update()
key pressed in Update()
key pressed in Update()
key pressed in FixedUpdate()
key pressed in Update()
key pressed in Update()
key pressed in Update()
key pressed in FixedUpdate()
key pressed in Update()
key pressed in Update()
key pressed in FixedUpdate()
key pressed in Update()
key pressed in FixedUpdate()
key pressed in Update()
What’s the best way to approach this problem? I suppose you could argue that asking for keypresses in FixedUpdate() is wrong, but I have to put my physics code in FixedUpdate().