Skip to content

Commit

Permalink
FIXED character floating in midair when hitting a ceiling during a jump.
Browse files Browse the repository at this point in the history
	Jumping speed is set to 0 after the character is stuck with the same
	z coordinate for a number of frames when vertical velocity is
	positive, currently 3.

FIXED missing return value in world::character::put_state
  • Loading branch information
mkalinski committed Aug 4, 2011
1 parent 49ea9ac commit 51a6968
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/world/character.cc
Expand Up @@ -93,6 +93,10 @@ void character::jump()
// process character movement
bool character::update ()
{
// saving the vertical position before movement
s_int32 prev_z = z ();
static u_int32 frames_stuck = 0;

// character movement
Schedule.update ();

Expand All @@ -105,6 +109,7 @@ bool character::update ()
if (GroundPos == z())
{
VSpeed = 0;
frames_stuck = 0; // reset counter for next jump

// character no longer jumping or falling
if (IsRunning != ToggleRunning)
Expand All @@ -122,7 +127,15 @@ bool character::update ()
}
}
}
else if (VSpeed > 0) VSpeed -= 0.4;
else if (VSpeed > 0)
{
// if vertical velocity is positive and we're not rising, we may have hit something
// but if we did eventually move, reset counter
frames_stuck = vz() > 0 && z () == prev_z ? frames_stuck + 1 : 0;

// if we're stuck for more then X frames in a row, assume we've hit the ceiling
VSpeed = frames_stuck > 2 ? 0 : VSpeed - 0.4;
}

return true;
}
Expand Down Expand Up @@ -275,7 +288,9 @@ bool character::put_state (base::flat & file) const
// save schedule
base::flat record;
Schedule.put_state (record);
file.put_flat ("schedule", record);
file.put_flat ("schedule", record);

return true;
}

// load from stream
Expand Down

0 comments on commit 51a6968

Please sign in to comment.