I have a stupid question. If I have a simple “character” entity with a MeshInstanceRenderComponent and an associated mesh, how do I offset the mesh so that the base of the character is at the bottom of the mesh (the feet) rather than the center of the mesh?
Outside of ECS, in pure gameObject terms, if I had a “character” gameObject and wanted its base position to be at its “feet”, I would create an empty parent gameObject and a child gameObject with a mesh. Then I would just set the transform of the child gameObject so that it was moved “up” relative to the parent gameObject. I don’t know the best approach for doing this in ECS.
the best approach here is to edit mesh itself to have proper position
option 2 is to move the entity the same way you do it with GameObjects
there is an example of a hierarchy in samples repo
1 Like
ECS has hierarchy logic, with parent/child, you can do same as in default unity approach.
2 Likes
Thanks for the replies, I ended up setting up the relationship entirely in code with the Attach component, I guess this is “pure” ECS
var parent = entityManager.CreateEntity(Bootstrap.PeasantArchetype);
var child = entityManager.CreateEntity(typeof(Position), typeof(Scale));
var attach = entityManager.CreateEntity(typeof(Attach));
entityManager.SetComponentData(parent, new Position { Value = spawnPosition });
entityManager.SetComponentData(parent, new MoveAgent(MoveAgentStatus.Idle, Bootstrap.Settings.enemySpeed, 0, 0, 0, 0, spawnPosition));
entityManager.SetComponentData(child, new Position { Value = new float3(0, 1, 0) });
entityManager.SetComponentData(child, new Scale { Value = new float3(1, 10, 1) });
entityManager.AddSharedComponentData(child, Bootstrap.PeasantLook);
entityManager.SetComponentData(attach, new Attach { Parent = parent, Child = child });
1 Like