From ec2f53b03ec60d056c84e7400647d80528d62fe8 Mon Sep 17 00:00:00 2001 From: alpererdin Date: Thu, 17 Oct 2024 03:43:29 +0300 Subject: [PATCH] Updated small cubes' positions using LocalToWorld instead of LocalTransform. --- .../Assets/HelloCube/6. Reparenting/ReparentingSystem.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/EntitiesSamples/Assets/HelloCube/6. Reparenting/ReparentingSystem.cs b/EntitiesSamples/Assets/HelloCube/6. Reparenting/ReparentingSystem.cs index db933a271..dd369c11f 100644 --- a/EntitiesSamples/Assets/HelloCube/6. Reparenting/ReparentingSystem.cs +++ b/EntitiesSamples/Assets/HelloCube/6. Reparenting/ReparentingSystem.cs @@ -60,12 +60,16 @@ public void OnUpdate(ref SystemState state) // Attach all the small cubes to the rotator by adding a Parent component to the cubes. // (The next time TransformSystemGroup updates, it will update the Child buffer and transforms accordingly.) - foreach (var (transform, entity) in - SystemAPI.Query>() + var parentLocalToWorld = SystemAPI.GetComponent(rotatorEntity); + + foreach (var (localToWorld, entity) in + SystemAPI.Query>() .WithNone() .WithEntityAccess()) { ecb.AddComponent(entity, new Parent { Value = rotatorEntity }); + float3 localPosition = math.transform(math.inverse(parentLocalToWorld.Value), localToWorld.ValueRO.Position); + ecb.SetComponent(entity, new LocalTransform { Position = localPosition, Rotation = quaternion.identity, Scale = 0.5f }); } // Alternative solution instead of the above loop: