This commit is contained in:
aozhiwei 2023-01-05 11:34:29 +08:00
parent 676f69e15c
commit 4b9fb4a4d7
4 changed files with 14 additions and 11 deletions

View File

@ -651,7 +651,7 @@ void Bullet::ProcFlyHook(Entity* target)
}
CreatureWeakPtr sender_bk = sender;
int ok_buff_id = gun_meta->_int_param1;
c->AutoNavigation(born_pos, gun_meta->bullet_speed() * 2,
c->AutoNavigation(born_pos.ToGlmVec3(), gun_meta->bullet_speed() * 2,
[buff_uniids, ok_buff_id, sender_bk] (Creature* c) mutable
{
for (int buff_uniid : buff_uniids) {
@ -663,7 +663,7 @@ void Bullet::ProcFlyHook(Entity* target)
}
);
} else {
sender.Get()->AutoNavigation(GetPos(), gun_meta->bullet_speed() * 2,
sender.Get()->AutoNavigation(GetPos().ToGlmVec3(), gun_meta->bullet_speed() * 2,
[] (Creature* c)
{
@ -885,7 +885,7 @@ void Bullet::ProcNormalBullet(BulletCheckResult& result)
if (!hited) {
if (raycast_hited) {
if (result.flyed_distance > 0.001f) {
sender.Get()->AutoNavigation(GetPos(), gun_meta->bullet_speed() * 2,
sender.Get()->AutoNavigation(raycast_hit_point_, gun_meta->bullet_speed() * 2,
[] (Creature* c)
{
@ -972,6 +972,7 @@ void Bullet::Raycast()
if (ret) {
raycast_hited = true;
sender.Get()->room->map_instance->UnScale(hit_point);
raycast_hit_point_ = hit_point;
raycast_len_ = GlmHelper::Norm(hit_point - born_pos.ToGlmVec3());
}
}

View File

@ -92,6 +92,7 @@ private:
bool raycasted_ = false;
bool raycast_hited = false;
float raycast_len_ = 0.0f;
glm::vec3 raycast_hit_point_ = glm::vec3(0.0f, 0.0f, 0.0f);
friend class EntityFactory;
};

View File

@ -2530,10 +2530,10 @@ void Creature::_UpdateSpecMove()
}
}
void Creature::AutoNavigation(Position target_pos, float speed,
void Creature::AutoNavigation(const glm::vec3& target_pos, float speed,
std::function<void (Creature*)> cb)
{
float distance = GetPos().Distance2D2(target_pos);
float distance = GetPos().DistanceGlmVec3(target_pos);
if (distance < 0.001f) {
cb(this);
return;
@ -2547,7 +2547,7 @@ void Creature::AutoNavigation(Position target_pos, float speed,
{
CreatureWeakPtr c;
Position src_pos;
Position target_pos;
glm::vec3 target_pos;
glm::vec3 dir;
int exec_frameno = 0;
float speed = 0.0f;
@ -2558,7 +2558,7 @@ void Creature::AutoNavigation(Position target_pos, float speed,
context->c = GetWeakPtrRef();
context->src_pos = GetPos();
context->target_pos = target_pos;
context->dir = GetPos().CalcDir(target_pos);
context->dir = target_pos - GetPos().ToGlmVec3();
GlmHelper::Normalize(context->dir);
context->speed = speed;
context->distance = distance;
@ -2575,7 +2575,7 @@ void Creature::AutoNavigation(Position target_pos, float speed,
Room* room = context->c.Get()->room;
Creature* c = context->c.Get();
glm::vec3 dir = c->GetPos().CalcDir(context->target_pos);
glm::vec3 dir = context->target_pos - c->GetPos().ToGlmVec3();
GlmHelper::Normalize(dir);
Position old_pos = c->GetPos();
float move_length = context->speed / (float)SERVER_FRAME_RATE;
@ -2587,7 +2587,7 @@ void Creature::AutoNavigation(Position target_pos, float speed,
Global::Instance()->verify_set_pos = 0;
#ifdef DEBUG
a8::XPrintf("speed:%d src_pos:%f,%f,%f new_pos:%f,%f,%f move_distance:%f\n",
a8::XPrintf("speed:%d src_pos:%f,%f,%f new_pos:%f,%f,%f move_distance:%f src_distance:%f\n",
{
context->speed,
context->src_pos.x,
@ -2596,7 +2596,8 @@ void Creature::AutoNavigation(Position target_pos, float speed,
new_pos.x,
new_pos.y,
new_pos.z,
move_distance
move_distance,
context->distance
});
#endif
bool ok = std::abs(move_distance - context->distance) < 0.0001f;

View File

@ -282,7 +282,7 @@ class Creature : public MoveableEntity
float GetAttrAbs(int attr_id);
float GetAttrRate(int attr_id);
void RecalcDtoAttr();
void AutoNavigation(Position target_pos, float speed,
void AutoNavigation(const glm::vec3& target_pos, float speed,
std::function<void (Creature*)> cb);
void AddTraceBullet(int bullet_uniid, int target_uniid, int gun_id);
void LockAttackDir(int time);