Basically I want to make gravity system in Rust Bevy for my player, but I can't figure out how can I do that so I came up with this idea to multiply the -y
value with the seconds.
If you have any other idea please tell me.
Hope you understand what I'm trying to say.
fn player_2_keyboard_event_system(
kb: Res<Input<KeyCode>>,
mut query: Query<&mut Velocity2, With<Player2>>,
time: Res<Time>,
) {
if let Ok(mut velocity2) = query.get_single_mut() {
velocity2.x = if kb.pressed(KeyCode::A) {
-1.
} else if kb.pressed(KeyCode::D) {
1.
} else {
0.
};
if let Ok(mut velocity2) = query.get_single_mut() {
velocity2.y = if kb.pressed(KeyCode::S) {
-1.
} else if kb.pressed(KeyCode::W) {
1.
} else {
-0.1 * time.delta_seconds() // Something like this!!!
}
}
}
}
I was trying to make gravity in Rust Using Bevy-Engine, but I can't figure out how I can do that. So I came up with this idea.