feat: sync entity direction and rotate models accordingly

Move direction into the transform component and include it in server-to-client entity updates. Client now sets transform direction from the network message and uses it to compute yaw for model rotation, so entities visually face their movement direction. Refactor net_utils to support arbitrary Vec3 fields.
This commit is contained in:
2026-08-04 10:46:31 +08:00
parent 6b1f9d7354
commit e2bbc2d57f
12 changed files with 37 additions and 18 deletions

View File

@@ -49,6 +49,7 @@ void ClientEntityManager::handle_entity_update(UpdateInfo& info) {
auto creature = m_registry.try_get<BaseClientCreature>(e);
ASSERT(creature);
creature->transform.position.value = info.pos;
creature->transform.direction.value = info.direction;
}
void ClientEntityManager::receive_entity_create(S2CEntityCreate& s2c) {
@@ -66,7 +67,8 @@ void ClientEntityManager::receive_entity_destory(EntityID id) {
void ClientEntityManager::receive_entity_update(S2CEntityUpdate& msg) {
UpdateInfo e;
e.id = msg.id();
e.pos = Tools::get_net_pos(msg.pos());
e.pos = Tools::get_net_vec3(msg.pos());
e.direction = Tools::get_net_vec3(msg.direction());
m_tasks.emplace(Command::UPDATE, std::move(e));
}