This commit is contained in:
aozhiwei 2022-11-30 13:39:33 +08:00
parent 140761a8d2
commit e298ca53f1
2 changed files with 31 additions and 7 deletions

View File

@ -4,6 +4,8 @@
#include "moveableentity.h"
#include "room.h"
#include "mapinstance.h"
#include "creature.h"
#include "metamgr.h"
MoveHelper::MoveHelper(class MoveableEntity* owner)
{
@ -31,16 +33,36 @@ void MoveHelper::CalcTargetPos(float distance)
end.z = target_pos2d.y / 10.0f;
MovePathPoint point;
int ret = owner_->room->map_instance->Raycast(0, start, end, hit_point);
if (ret > 1) {
point.pos = hit_point * 10.f;
Creature* c = (Creature*)owner_;
if (c->HasBuffEffect(kBET_ThroughWall) ||
c->HasBuffEffect(kBET_Fly)) {
point.tar_pos = end * 10.f;
if (point.tar_pos.x > owner_->room->GetMapMeta()->i->map_width() + 10) {
point.tar_pos.x = owner_->room->GetMapMeta()->i->map_width() - 10;
}
if (point.tar_pos.z > owner_->room->GetMapMeta()->i->map_height() + 10) {
point.tar_pos.z = owner_->room->GetMapMeta()->i->map_height() - 10;
}
if (point.tar_pos.x < 10) {
point.tar_pos.x = 10;
}
if (point.tar_pos.y < 10) {
point.tar_pos.y = 10;
}
} else {
point.pos = end * 10.f;
int ret = owner_->room->map_instance->Raycast(0, start, end, hit_point);
if (ret > 1) {
point.tar_pos = hit_point * 10.f;
} else {
point.tar_pos = end * 10.f;
}
}
a8::Vec2 v2;
v2.x = point.pos.x;
v2.y = point.pos.z;
v2.x = point.tar_pos.x;
v2.y = point.tar_pos.z;
point.distance = v2.Distance(owner_->GetPos());
point.src_pos.x = owner_->GetPos().x;
point.src_pos.z = owner_->GetPos().y;
paths_.push_back(point);
}

View File

@ -2,7 +2,9 @@
struct MovePathPoint
{
glm::vec3 pos;
glm::vec3 src_pos;
glm::vec3 tar_pos;
glm::vec3 dir;
float distance = 0.0f;
};