This commit is contained in:
aozhiwei 2023-02-03 16:55:51 +08:00
parent 99aeb06d16
commit 0efe12e24f
4 changed files with 30 additions and 5 deletions

View File

@ -2394,10 +2394,10 @@ void Creature::SpecDirMove(glm::vec3 dir, float distance)
if (ret) {
room->map_instance->UnScale(hit_point);
GetMutablePos().FromGlmVec3(hit_point);
room->map_instance->CheckTerrain(this, same_polys_flags, spec_polys);
}
room->grid_service->MoveCreature(this);
//CheckSpecObject();
GetMovement()->ClearPath();
}

View File

@ -15,6 +15,7 @@
#include "mapmgr.h"
#include "room.h"
#include "entityfactory.h"
#include "creature.h"
#include "mt/MetaMgr.h"
#include "mt/Param.h"
#include "mt/Map.h"
@ -695,7 +696,31 @@ bool MapInstance::RaycastEx(const glm::vec3& start, const glm::vec3& end,
return true;
}
int MapInstance::GetPolyFlags(Creature* c, int same_polys_flags, const std::vector<dtPolyRef>& spec_polys)
void MapInstance::CheckTerrain(Creature* c, int same_poly_flags, const std::vector<dtPolyRef>& spec_polys)
{
if (same_poly_flags) {
c->CheckSpecObject(same_poly_flags);
} else {
if (spec_polys.empty()) {
c->CheckSpecObject(0);
} else {
float pos[3];
pos[0] = c->GetPos().x;
pos[1] = c->GetPos().y;
pos[2] = c->GetPos().z;
float closest[3];
for (auto& poly_ref : spec_polys) {
dtStatus status = navmesh_query_->closestPointOnPolyBoundary(poly_ref, pos, closest);
if (dtStatusSucceed(status) &&
std::fabs(closest[0] - c->GetPos().x) <= 0.3f &&
std::fabs(closest[2] - c->GetPos().z) <= 0.3f) {
unsigned short flags = 0;
if (dtStatusSucceed(navmesh_->getPolyFlags(poly_ref, &flags))) {
c->CheckSpecObject(flags);
break;
}
}
}
}
}
}

View File

@ -43,7 +43,7 @@ class MapInstance : public std::enable_shared_from_this<MapInstance>
void Scale(glm::vec3& v);
void UnScale(glm::vec3& v);
glm::vec3 UnScaleEx(const glm::vec3& v);
int GetPolyFlags(Creature* c, int same_polys_flags, const std::vector<dtPolyRef>& spec_polys);
void CheckTerrain(Creature* c, int same_poly_flags, const std::vector<dtPolyRef>& spec_polys);
private:
void CreateThings();

View File

@ -27,7 +27,7 @@ bool Movement::UpdatePosition()
{
curr_point.curr_pos.AddGlmVec3(curr_point.dir * owner_->GetSpeed());
owner_->SetPos(curr_point.curr_pos);
//owner_->CheckSpecObject();
owner_->room->map_instance->CheckTerrain(owner_, curr_point.same_polys_flags, curr_point.spec_polys);
}
if (owner_->GetPos().Distance2D2(curr_point.src_pos) - curr_point.distance >= 0.0001f) {
curr_point.tar_pos.y = curr_point.curr_pos.y;