Skip to content

Commit

Permalink
fix objects colliding with its own collision boxes
Browse files Browse the repository at this point in the history
  • Loading branch information
sapier authored and sapier committed Apr 9, 2013
1 parent 7d002b6 commit 6e4fdf3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
13 changes: 9 additions & 4 deletions src/collision.cpp
Expand Up @@ -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");
Expand Down Expand Up @@ -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
Expand All @@ -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);
}
}
}
}
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/collision.h
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/content_cao.cpp
Expand Up @@ -1152,7 +1152,7 @@ class GenericCAO : public ClientActiveObject
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;
Expand Down
2 changes: 1 addition & 1 deletion src/content_sao.cpp
Expand Up @@ -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;
Expand Down

0 comments on commit 6e4fdf3

Please sign in to comment.