Skip to content

Commit 13a9fd2

Browse files
committed
physics fixup
1 parent 8b31fc1 commit 13a9fd2

3 files changed

Lines changed: 16 additions & 18 deletions

File tree

game/game/movealgo.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -860,10 +860,10 @@ void MoveAlgo::onMoveFailed(const Tempest::Vec3& dp, const DynamicWorld::Collisi
860860
if(std::abs(val)>threshold) {
861861
// emulate bouncing behaviour of original game
862862
Tempest::Vec3 corr;
863-
for(int i=5; i<=45; i+=5) {
863+
for(int i=5; i<=35; i+=5) {
864864
for(float angle:{float(i),-float(i)}) {
865-
applyRotation(corr,dp,float(angle*M_PI)/180.f);
866-
if(tryMove(corr.x,corr.y,corr.z)) {
865+
applyRotation(corr,dp+skipMove,float(angle*M_PI)/180.f);
866+
if(npc.tryMove(corr)) {
867867
if(forward)
868868
npc.setDirection(npc.rotation()+angle);
869869
return;

game/physics/dynamicworld.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ struct DynamicWorld::NpcBody : btRigidBody {
6161

6262
struct DynamicWorld::NpcBodyList final {
6363
struct Record final {
64-
NpcBody* body = nullptr;
65-
float x = 0.f;
64+
NpcBody* body = nullptr;
65+
float x = 0.f;
6666
};
6767

6868
NpcBodyList(DynamicWorld& wrld):wrld(wrld){
69-
body.reserve(1024);
69+
body .reserve(1024);
7070
frozen.reserve(1024);
7171
}
7272

@@ -88,9 +88,7 @@ struct DynamicWorld::NpcBodyList final {
8888
obj->setWorldTransform(trans);
8989
obj->setUserIndex(C_Ghost);
9090
obj->setFlags(btCollisionObject::CF_NO_CONTACT_RESPONSE);
91-
//obj->setCollisionFlags(btCollisionObject::CO_GHOST_OBJECT);
9291

93-
//world->addCollisionObject(obj);
9492
add(obj);
9593
resize(*obj,height,dx,dz);
9694
return obj;
@@ -652,7 +650,7 @@ DynamicWorld::NpcItem DynamicWorld::ghostObj(std::string_view visual) {
652650
}
653651
auto obj = npcList->create(min,max);
654652
float dim = std::max(obj->rX,obj->rZ);
655-
return NpcItem(this,obj,obj->h,dim*0.5f);
653+
return NpcItem(this,obj,dim*0.5f);
656654
}
657655

658656
DynamicWorld::Item DynamicWorld::staticObj(const PhysicMeshShape *shape, const Tempest::Matrix4x4 &m) {
@@ -955,22 +953,24 @@ bool DynamicWorld::NpcItem::tryMove(const Tempest::Vec3& dp, CollisionTest& out)
955953
if(!obj)
956954
return false;
957955

958-
auto prev = obj->pos;
959-
auto r = obj->r*100.f;
956+
auto initial = obj->pos;
957+
auto r = obj->r;
960958
int count = 1;
961959

962960
if(dp.quadLength()>r*r)
963961
count = int(std::ceil(dp.manhattanLength()/r));
964962

963+
auto prev = initial;
965964
for(int i=1; i<=count; ++i) {
966-
auto pos = prev+(dp*float(i))/float(count);
965+
auto pos = initial+(dp*float(i))/float(count);
967966
implSetPosition(pos);
968967
if(owner->hasCollision(*this,out)) {
969968
if(i>1) {
970969
// moved a bit
971-
break;
970+
setPosition(prev);
971+
return true;
972972
}
973-
implSetPosition(prev);
973+
implSetPosition(initial);
974974
if(owner->hasCollision(*this,out)) {
975975
// was in collision from the start
976976
setPosition(pos);

game/physics/dynamicworld.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,13 @@ class DynamicWorld final {
6060
struct NpcItem {
6161
public:
6262
NpcItem()=default;
63-
NpcItem(DynamicWorld* owner,NpcBody* obj,float h,float r):owner(owner),obj(obj),height(h),r(r){}
64-
NpcItem(NpcItem&& it):owner(it.owner),obj(it.obj),height(it.height),r(it.r){it.obj=nullptr;}
63+
NpcItem(DynamicWorld* owner,NpcBody* obj,float r):owner(owner),obj(obj),r(r){}
64+
NpcItem(NpcItem&& it):owner(it.owner),obj(it.obj),r(it.r){it.obj=nullptr;}
6565
~NpcItem();
6666

6767
NpcItem& operator = (NpcItem&& it){
6868
std::swap(owner,it.owner);
6969
std::swap(obj,it.obj);
70-
std::swap(height,it.height);
7170
std::swap(r,it.r);
7271
return *this;
7372
}
@@ -89,7 +88,6 @@ class DynamicWorld final {
8988
private:
9089
DynamicWorld* owner = nullptr;
9190
NpcBody* obj = nullptr;
92-
float height = 0.f;
9391
float r = 0.f;
9492
void implSetPosition(const Tempest::Vec3& pos);
9593

0 commit comments

Comments
 (0)