修复movement问题

This commit is contained in:
aozhiwei 2019-03-20 17:27:51 +08:00
parent df791a4fd7
commit 7ea450c80c
3 changed files with 27 additions and 1 deletions

View File

@ -7,7 +7,13 @@ void MovementComponent::Update(int delta_time)
{
if (path_index_ < paths_.size()) {
MovePathPoint& target_point = paths_[path_index_];
owner->pos = owner->pos + (target_point.pos - owner->pos) * delta_time * move_speed_;
if (owner->pos == target_point.pos) {
++path_index_;
return;
}
Vector2D path = target_point.pos - owner->pos;
float distance = path.Norm();
owner->pos = owner->pos + path.Normalize() * std::min(move_speed_, distance);
if (owner->pos == target_point.pos) {
++path_index_;
}

View File

@ -67,7 +67,16 @@ void Room::AddPlayer(Player* hum)
uniid_hash_[hum->entity_uniid] = hum;
moveable_hash_[hum->entity_uniid] = hum;
accountid_hash_[hum->account_id] = hum;
human_hash_[hum->entity_uniid] = hum;
++alive_count_;
for (auto& pair : human_hash_) {
if (pair.second != hum) {
pair.second->new_players.insert(hum);
pair.second->part_players.insert(hum);
hum->new_players.insert(pair.second);
hum->part_players.insert(pair.second);
}
}
}
unsigned short Room::AllocUniid()
@ -94,7 +103,17 @@ void Room::ShuaAndroid()
hum->Initialize();
uniid_hash_[hum->entity_uniid] = hum;
moveable_hash_[hum->entity_uniid] = hum;
human_hash_[hum->entity_uniid] = hum;
++alive_count_;
for (auto& pair : human_hash_) {
if (pair.second != hum) {
pair.second->new_players.insert(hum);
pair.second->part_players.insert(hum);
hum->new_players.insert(pair.second);
hum->part_players.insert(pair.second);
}
}
}
}

View File

@ -62,4 +62,5 @@ private:
std::map<std::string, Player*> accountid_hash_;
std::map<unsigned short, Entity*> uniid_hash_;
std::map<unsigned short, Entity*> moveable_hash_;
std::map<unsigned short, Human*> human_hash_;
};