Just a small hint: In your implementation the player movement is currently dependent on the actual framerate the game is running with. I.e. if the framerate is low, the player moves slow and vice versa.
You'd probably want to calculate the translation difference based on the time that passed, by passing a Time into the system, like:
fnplayer_movement(keyboard_input:Res<Input<KeyCode>>,time:Res<Time>,mutquery:Query<(&mutTransform,&Player)>,){letv=200.0;// velocity in units per second, v = ds / dt => ds = v * dtletdelta=v*time.delta_seconds;for(muttransform,_player)in&mutquery.iter(){lettranslation=transform.translation_mut();ifkeyboard_input.pressed(KeyCode::Right){*translation.x_mut()+=delta;}}}
With this, the player will always be moved the right distance after a rendering update, no matter how high the framerate.
Yup, thanks for pointing that out! I didn't want to add too much complexity to this first example, but I'm definitely going to point this out in the next article.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Nice article, thanks!
Just a small hint: In your implementation the player movement is currently dependent on the actual framerate the game is running with. I.e. if the framerate is low, the player moves slow and vice versa.
You'd probably want to calculate the translation difference based on the time that passed, by passing a Time into the system, like:
With this, the player will always be moved the right distance after a rendering update, no matter how high the framerate.
Yup, thanks for pointing that out! I didn't want to add too much complexity to this first example, but I'm definitely going to point this out in the next article.