Open nicholas-maltbie opened 3 years ago
Notes on transforming into props
// If the floor has a MovementTracking component, set the parent of
// the player entity to be the floor so the player can move along
// with the floor
if (changedParent && !grounded.Falling && movementTrackingGetter.HasComponent(grounded.hitEntity))
{
// Taken from this conversation https://forum.unity.com/threads/how-to-convert-localtoworld-to-localtoparent.845725/
LocalToWorld parentLTW = localToWoldGetter[grounded.hitEntity];
LocalToWorld childLTW = localToWoldGetter[entity];
RigidTransform localToWorld_parent = new RigidTransform(parentLTW.Value);
RigidTransform localToWorld_child = new RigidTransform(childLTW.Value);
RigidTransform worldToParent = math.inverse(localToWorld_parent);
RigidTransform localToParent = math.mul(worldToParent, localToWorld_child);
LocalToParent newLocalToParent = new LocalToParent { Value = new float4x4(localToParent) };
Parent newParent = new Parent { Value = grounded.hitEntity };
if (!parentGetter.HasComponent(entity))
{
ecbParallelWriter.AddComponent<Parent>(entityInQueryIndex, entity, newParent);
}
else
{
ecbParallelWriter.SetComponent<Parent>(entityInQueryIndex, entity, newParent);
}
if (!localToParentGetter.HasComponent(entity))
{
ecbParallelWriter.AddComponent<LocalToParent>(entityInQueryIndex, entity, newLocalToParent);
}
else
{
ecbParallelWriter.SetComponent<LocalToParent>(entityInQueryIndex, entity, newLocalToParent);
}
ecbParallelWriter.SetComponent<Translation>(entityInQueryIndex, entity, new Translation { Value = localToParent.pos });
ecbParallelWriter.SetComponent<Rotation>(entityInQueryIndex, entity, new Rotation { Value = localToParent.rot });
}
else
{
if (parentGetter.HasComponent(entity))
{
LocalToWorld childLTW = localToWoldGetter[entity];
RigidTransform localToWorld_child = new RigidTransform(childLTW.Value);
ecbParallelWriter.SetComponent<Translation>(entityInQueryIndex, entity, new Translation { Value = localToWorld_child.pos });
ecbParallelWriter.SetComponent<Rotation>(entityInQueryIndex, entity, new Rotation { Value = localToWorld_child.rot });
ecbParallelWriter.RemoveComponent<Parent>(entityInQueryIndex, entity);
ecbParallelWriter.RemoveComponent<LocalToParent>(entityInQueryIndex, entity);
}
}
Components to add
This should work by whenever a command is given (this can be a simple debug for the purposes of this issue), a player should delete their current disguise and create a new disguise of a given prop. This will involve three main steps.
This may involve multiple systems, libraries, or static references to coordinate all of these references and objects depending on the easiest code implementation.