#Rotating unscaled parent object deforms children

1 messages · Page 1 of 1 (latest)

topaz sparrow
#

Hey Guys,
I try to simply rotate my entities towards a target in a smooth way, but using local or world rotation, my entity deforms during rotation.
Normally this happens when one tries to rotate a scaled object, but i have a parent empty entity which is not scaled or rotated at all... heres my rotation code:

  public void RotateToTarget(float deltaTime) {
        var rotTarget = Quaternion.LookRotation(moveTarget.ValueRO.position - unitTf.WorldPosition, unitTf.Up);
        unitTf.WorldRotation = Quaternion.Slerp(unitTf.WorldRotation, rotTarget, speed.ValueRO.angular * deltaTime);        
    }
#

my child objects are scaled though

#

nvm i fixed it...
when spawning my entities i initialized them with LocalTransform, should be WorldTransform instead:

 var spawnedEntity = buffer.Instantiate(0, spawnZone.ValueRW.UnitPrefab);
            buffer.SetComponent(1, spawnedEntity, new WorldTransform {
                Position = new float3(x, 0, z),
                Scale = 1,
            });
#

i assume setting local transform will result in a calculated world transform which has different scaling etc.