0

I am looking for a cleaner pattern to storing character position data, offsets, and transformations. I currently have a character with a vec3 for position.

Entity{
 position: vec3
 rotation: vec4Quaternion
 velocity: vec3
}

I use this position vector as the world coordinate. So that when Y=0 I imagine the characters feet are on the ground. This makes it easier to think about where the entity is in world space.

The problem I am having is that mesh entities like colliders or the skin mesh will assume a position vector at the center of the mesh. This is causing me to have to do a bunch of transformation juggling. I can't 1-to-1 map these meshes to the entities world position.

I will update my characters 'ground position' when they move. then have to calculate the new 'center position' which is calculated like

centerPosition = [
groundPosition.x
groundPosition.y + entityHeight/2,
groundPosition.z
]

I"m wondering if there is a better pattern for this. Maybe I assume the entities position vector is a 'center position' as well? but not clear to me how to handle the ground offset in that case.

kevzettler
  • 278
  • 1
  • 2
  • 19
  • 1
    It's not necessary that the center of a collider component is the center of the parent entity. In fact, it's common that we want to represent an entity with multiple collision shapes, at various offsets from its center (say, a tree with a capsule trunk and a crown represented by several spheres). So you might not need this one variable to do double-duty. – DMGregory Apr 07 '20 at 22:41
  • @DMGregory thats a good point. I guess I need a better understanding of how to store child positions relative to a parent entity – kevzettler Apr 07 '20 at 23:03
  • 2
  • @DMGregory yes that looks very helpful will review. – kevzettler Apr 07 '20 at 23:06

0 Answers0