So I am setting an arrow to the be the child of a human, so that the arrow is stuck in the human and rotates with him when he moves. My problem is trying to set the rotation once the arrow has been made a child.
Setting Rotation:
ecb.SetComponent(Arrow, new Rotation { Value = math.mul(LocalToWorlds[Arrow].Rotation, math.inverse(LocalToWorlds[Human].Rotation)) });
Setting Position:
ecb.SetComponent(Arrow, new Translation { Value = LocalToWorlds[Arrow].Position - LocalToWorlds[Human].Position });
Sadly this doesn’t produce the rotation expected, I think the translation is correct.
Not sure what are you trying to do. What is the result?
Why not setting Rotation to quaternion.zero and let transform systems do their job?
Also, try changing order of quaternion multiplication, it’s important in some cases.
Where B is the projectile, an arrow for example and A is the body it is hitting and sticking in to. Var d makes sure that the scale is properly resolved too.
var a = new RigidTransform(LocalToWorlds[entityA].Value);
var d = math.inverse(a);
var b = new Translation { Value = math.transform(d, LocalToWorlds[entityB].Position) };
var c = new Rotation { Value = math.mul(d.rot, LocalToWorlds[entityB].Rotation) };
ecb.SetComponent(entityB, c);
ecb.SetComponent(entityB, b);