@@ -61,12 +61,12 @@ struct DynamicWorld::NpcBody : btRigidBody {
6161
6262struct 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
658656DynamicWorld::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);
0 commit comments