Skip to content

Commit ddb8cf8

Browse files
committed
collision fixup
1 parent ca2fecc commit ddb8cf8

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

game/physics/dynamicworld.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -934,8 +934,12 @@ bool DynamicWorld::NpcItem::testMove(const Tempest::Vec3& dst, const Tempest::Ve
934934
auto dp = dst-pos0;
935935
int count = 1;
936936

937-
if(dp.quadLength()>obj->r*obj->r)
938-
count = int(std::ceil(dp.manhattanLength()/obj->r));
937+
if((dp.x*dp.x+dp.z*dp.z)>r*r || dp.y>obj->h*0.5f) {
938+
const int countXZ = int(std::ceil(std::sqrt(dp.x*dp.x+dp.z*dp.z)/r));
939+
const int countY = int(std::ceil(std::abs(dp.y)/(obj->h*0.5f)));
940+
941+
count = std::max(countXZ,countY);
942+
}
939943

940944
for(int i=1; i<=count; ++i) {
941945
auto pos = pos0+(dp*float(i))/float(count);
@@ -953,12 +957,16 @@ bool DynamicWorld::NpcItem::tryMove(const Tempest::Vec3& dp, CollisionTest& out)
953957
if(!obj)
954958
return false;
955959

956-
auto initial = obj->pos;
957-
auto r = obj->r;
958-
int count = 1;
960+
auto initial = obj->pos;
961+
auto r = obj->r;
962+
int count = 1;
959963

960-
if(dp.quadLength()>r*r)
961-
count = int(std::ceil(dp.manhattanLength()/r));
964+
if((dp.x*dp.x+dp.z*dp.z)>r*r || dp.y>obj->h*0.5f) {
965+
const int countXZ = int(std::ceil(std::sqrt(dp.x*dp.x+dp.z*dp.z)/r));
966+
const int countY = int(std::ceil(std::abs(dp.y)/(obj->h*0.5f)));
967+
968+
count = std::max(countXZ,countY);
969+
}
962970

963971
auto prev = initial;
964972
for(int i=1; i<=count; ++i) {

0 commit comments

Comments
 (0)