From 384ea0f7a1bdd441fd879edd97ebd84657168ee13a62323f238daad484b7f0df Mon Sep 17 00:00:00 2001 From: Stef Date: Wed, 24 Dec 2025 10:48:52 +0100 Subject: [PATCH] Added system that makes objects move based on their velocity. --- app/src/main.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app/src/main.rs b/app/src/main.rs index c9dd56c..f85f667 100644 --- a/app/src/main.rs +++ b/app/src/main.rs @@ -1,4 +1,5 @@ use bevy::color::palettes::basic::RED; +use bevy::log; use bevy::prelude::*; // Core Bevy types @@ -6,6 +7,7 @@ fn main() { App::new() .add_plugins(DefaultPlugins) .add_systems(Startup, setup) + .add_systems(Update, velocity_timestep) .run(); } @@ -15,7 +17,16 @@ fn setup(mut commands: Commands, mut meshes: ResMut>, mut materials let shape =meshes.add(Circle::new(50.0)); - commands.spawn((Mesh2d(shape.clone()), MeshMaterial2d(materials.add(Color::from(RED))), Transform::from_xyz(100.0, 0.0, 0.0))); + commands.spawn((Mesh2d(shape.clone()), MeshMaterial2d(materials.add(Color::from(RED))), Transform::from_xyz(100.0, 0.0, 0.0), Velocity(vec3(0.0, 100.0, 0.0)))); - commands.spawn((Mesh2d(shape.clone()), MeshMaterial2d(materials.add(Color::from(RED))), Transform::from_xyz(0.0, 0.0, 0.0))); + commands.spawn((Mesh2d(shape.clone()), MeshMaterial2d(materials.add(Color::from(RED))), Transform::from_xyz(0.0, 0.0, 0.0), Velocity(vec3(0.0, 100.0, 0.0)))); +} + +#[derive(Component)] +struct Velocity(Vec3); + +fn velocity_timestep(time: Res