-
I wrote a demo, but it seems there is no difference between the two use std::f32::consts::PI;
use bevy::prelude::*;
#[derive(Component)]
struct Parent;
#[derive(Component)]
struct Child;
#[derive(Component)]
struct RotateLocal;
fn setup(
mut command: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<ColorMaterial>>,
) {
command.spawn(Camera2d);
command.spawn((
Parent,
Mesh2d(meshes.add(Rectangle::new(100.0, 100.0))),
MeshMaterial2d(materials.add(Color::srgb(0.0, 1.0, 0.0))),
Transform::from_xyz(-100.0, 100.0, 0.0),
children![(
Child,
Mesh2d(meshes.add(Rectangle::new(20.0, 20.0))),
MeshMaterial2d(materials.add(Color::srgb(1.0, 1.0, 0.0))),
Transform::from_xyz(50.0, 50.0, 0.0),
)],
));
}
fn rotate_child(mut transform: Single<&mut Transform, With<Child>>) {
// are there any differencies?
// transform.rotate_local_z(PI / 180.0);
transform.rotate_z(PI / 180.0);
}
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.add_systems(Update, rotate_child)
.run();
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Here you're applying a rotation to the identity rotation (i.e. no initial rotation) and only rotating about the Z axis. In this case, the local Z axis and the global Z axis (or specifically the Z axis relative to the parent since this is a child entity) are always the same. If you make the initial |
Beta Was this translation helpful? Give feedback.
Here you're applying a rotation to the identity rotation (i.e. no initial rotation) and only rotating about the Z axis. In this case, the local Z axis and the global Z axis (or specifically the Z axis relative to the parent since this is a child entity) are always the same. If you make the initial
Transform
rotated about the X or Y axis by some amount, you'll see thatrotate_z
androtate_local_z
will then behave differently since the local and global Z axes would no longer be aligned.