For example, I have this simple piece of code which spawns a rectangle relative to its parent which is a circle:
commands
.spawn((MaterialMesh2dBundle {
mesh: meshes.add(shape::Circle::default().into()).into(),
material: materials.add(ColorMaterial::from(BALL_COLOR)),
transform: Transform::from_translation(Vec3::new(10., 10., 0.)).with_scale(Vec3::new(50., 50., 1.)),
..default()
},
Ball)).with_children( |parent| {
parent.spawn((
SpriteBundle{
transform: Transform {
translation: Vec3::new(2., 0., 1.),
scale: Vec3::new(0.2, 0.2, 1.),
..default()
},
sprite: Sprite {
color: RECT_COLOR,
..default()
},
..default()
},
Rect
));
});
I have a system which prints out both translations for both the Transform and the GlobalTransform of each of these shapes. For the ball entity the system prints: ball transform xy: [10, 10], ball global xy: [10, 10]. This is expected because the ball has no parent. However, for the rectangle the system prints: rect transform xy: [2, 0], rect global xy: [110, 10]. I would expect the child transform to be a simple addition onto the parent transform and print: rect transform xy: [2, 0], rect global xy: [12, 10] but that is not the case. So what is the relationship between the two? The extra 100 in the x value of the GlobalTransform of the child, the 2 in the Transform and the 50 as the width of the circle make me think its relative to the size of circle somehow. Is that the case?
