fix objects colliding with its own collision boxes 637/head
authorsapier <Sapier at GMX dot net>
Tue, 9 Apr 2013 21:16:13 +0000 (23:16 +0200)
committersapier <Sapier at GMX dot net>
Tue, 9 Apr 2013 21:16:13 +0000 (23:16 +0200)
src/collision.cpp
src/collision.h
src/content_cao.cpp
src/content_sao.cpp

index cd170196f4ef17e5b10666b0b3cbe9af79c28a6f..673966b6e89df679588db04949fa9cad7b04031b 100644 (file)
@@ -192,7 +192,7 @@ bool wouldCollideWithCeiling(
 collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
                f32 pos_max_d, const aabb3f &box_0,
                f32 stepheight, f32 dtime,
-               v3f &pos_f, v3f &speed_f, v3f &accel_f)
+               v3f &pos_f, v3f &speed_f, v3f &accel_f,ActiveObject* self)
 {
        Map *map = &env->getMap();
        //TimeTaker tt("collisionMoveSimple");
@@ -300,7 +300,9 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
                        c_env->getActiveObjects(pos_f,distance * 1.5,clientobjects);
                        for (int i=0; i < clientobjects.size(); i++)
                        {
-                               objects.push_back((ActiveObject*)clientobjects[i].obj);
+                               if ((self == 0) || (self != clientobjects[i].obj)) {
+                                       objects.push_back((ActiveObject*)clientobjects[i].obj);
+                               }
                        }
                }
                else
@@ -314,7 +316,9 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
                                for (std::set<u16>::iterator iter = s_objects.begin(); iter != s_objects.end(); iter++)
                                {
                                        ServerActiveObject *current = s_env->getActiveObject(*iter);
-                                       objects.push_back((ActiveObject*)current);
+                                       if ((self == 0) || (self != current)) {
+                                               objects.push_back((ActiveObject*)current);
+                                       }
                                }
                        }
                }
@@ -458,8 +462,9 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
                        if (is_object[nearest_boxindex]) {
                                info.type = COLLISION_OBJECT;
                        }
-                       else
+                       else {
                                info.type = COLLISION_NODE;
+                       }
                        info.node_p = node_positions[nearest_boxindex];
                        info.bouncy = bouncy;
                        info.old_speed = speed_f;
index 1178184567a3821f8a3d84397000fc8f908b0f85..77bf1f15d05ea32661197feb531af6233e50e836 100644 (file)
@@ -26,6 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 class Map;
 class IGameDef;
 class Environment;
+class ActiveObject;
 
 enum CollisionType
 {
@@ -70,7 +71,7 @@ struct collisionMoveResult
 collisionMoveResult collisionMoveSimple(Environment *env,IGameDef *gamedef,
                f32 pos_max_d, const aabb3f &box_0,
                f32 stepheight, f32 dtime,
-               v3f &pos_f, v3f &speed_f, v3f &accel_f);
+               v3f &pos_f, v3f &speed_f, v3f &accel_f,ActiveObject* self=0);
 
 #if 0
 // This doesn't seem to work and isn't used
index 9738dc34c24eee94deeeec96b00ff112aae1dec8..f79d0d6f62c78d63467b4b75180d6687aae33809 100644 (file)
@@ -1152,7 +1152,7 @@ public:
                                v3f p_acceleration = m_acceleration;
                                moveresult = collisionMoveSimple(env,env->getGameDef(),
                                                pos_max_d, box, stepheight, dtime,
-                                               p_pos, p_velocity, p_acceleration);
+                                               p_pos, p_velocity, p_acceleration,this);
                                // Apply results
                                m_position = p_pos;
                                m_velocity = p_velocity;
index e6c8c725c25ff82cd74ef514301ea1917d43d201..3526ecbd2edffb64fa6fc2978c247a6f19ba8a4b 100644 (file)
@@ -502,7 +502,7 @@ void LuaEntitySAO::step(float dtime, bool send_recommended)
                        v3f p_acceleration = m_acceleration;
                        moveresult = collisionMoveSimple(m_env,m_env->getGameDef(),
                                        pos_max_d, box, stepheight, dtime,
-                                       p_pos, p_velocity, p_acceleration);
+                                       p_pos, p_velocity, p_acceleration,this);
                        // Apply results
                        m_base_position = p_pos;
                        m_velocity = p_velocity;