-
Hi, So I was reading this example https://bevyengine.org/examples/2d-rendering/rotation/ and decide to try applying it to my case: fn startup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<ColorMaterial>>,
) {
let rocket_size = 10.0;
let x = 50.0;
commands.spawn((
RandomComponent,
RandomComponent(0.0),
Mesh2d(meshes.add(Triangle2d::new(
Vec2::new(x, rocket_size),
Vec2::new(x - rocket_size, 0.0),
Vec2::new(x + rocket_size, 0.0),
))),
MeshMaterial2d(materials.add(
Color::hsl(360. * 255 as f32 / 255 as f32, 0.95, 0.7)
)),
Transform::from(x, 0.0, 0.0)
));
} and the update rotation fn fn update_rocket_angle(
time: Res<Time>,
keys: Res<ButtonInput<KeyCode>>,
mut query: Query<(
& RandomComponent,
&mut Transform,
)>
) {
// Rotating Rocket Nose
// ========================================================================
let mut rotation_factor = 0.0;
// let mut movement_factor = 0.0;
if keys.pressed(KeyCode::ArrowLeft) {
rotation_factor += 1.0;
}
if keys.pressed(KeyCode::ArrowRight) {
rotation_factor -= 1.0;
}
for (randomComp, mut trans) in &mut query {
trans.rotate_z(rotation_factor * 5.0 * time.delta_secs());
}
} But instead of seen the triangle rotating on it's on center (like the Player's sprite on the example link) the Mesh2d Triangle is rotating around the screen origin. what am I missing here? Thank you for reading |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi, what does Transform::from(x, 0.0, 0.0) do? And how do you rotate around z? (trans.rotate_z) Best regards, |
Beta Was this translation helpful? Give feedback.
Thanks for the reply. Turns out my problem was the values being passed to the Triangle2d in the Mesh2d. The correct way would be to draw the triangle using values adjusted to the origin. That way when we execute the rotation the Mesh will rotate at "his own center".