i wanna keep the input in update but then how do i move the addforce stuff…i know u can make ur own function but if i just do this
if (Input.GetKeyDown(KeyCode.Space) && isGrounded == true)
{
AddForce();
}
then its stil called in update isnt it? id have to somehow move the fixedUpdate inside but i have other stuff in there so can somebody explain how people pull this off?
You only need to have continuous forces inside FixedUpdate. Any one time events are totally fine when applied in Update. Of course you can’t have GetKeyDown / Up events in FixedUpdate since it’s unreliable.
If the visual framerate is higher than the fixed update rate (50 ups by default) you might miss some key down / up events since FixedUpdate might not run every frame and one-time events are only true for one visual frame. If the visual framerate is lower than the fixed update rate you will sometimes get multiple FixedUpdate calls in a single visual frame so one-time events might be detected several times.
You generally could call AddForce from pretty much anywhere. Of course the effect of your applied force will take effect at the next FixedUpdate / Physics update.
Continuous forces should be applied in FixedUpdate to make the simulation deterministic and reliable. That said when you use GetKey to check the state of a key to apply a force, this should be done in FixedUpdate.