Skip to content

Commit

Permalink
Gloom: Simplified user physics
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent 9281501 commit e6c26fd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
6 changes: 3 additions & 3 deletions doomsday/tests/test_gloom/gloom/gloomwidget.cpp
Expand Up @@ -137,13 +137,13 @@ void GloomWidget::update()
const TimeSpan elapsed = d->previousUpdateAt.since();
d->previousUpdateAt = Time();

d->user.setInputState(d->inputs);
d->user.update(elapsed);

if (d->world)
{
d->world->update(elapsed);
}
d->user.setInputState(d->inputs);
d->user.update(elapsed);

d->updateModelView();
}

Expand Down
34 changes: 23 additions & 11 deletions doomsday/tests/test_gloom/gloom/world/user.cpp
Expand Up @@ -163,59 +163,71 @@ DENG2_PIMPL(User)
jumpPending = false;
}

if (world)
// Gravity.
momentum.y -= elapsed * 9.81f;

/*if (world)
{
// Gravity.
if (!onGround)
//if (!onGround)
{
momentum.y -= elapsed * 9.81f;
}
}
else
{
momentum.y = 0;
}
}*/

pos += momentum * elapsed;

if (world)
{
// Keep viewer on the ground.
float surface = world->groundSurfaceHeight(pos);
const float surface = world->groundSurfaceHeight(pos);

if (onGround)
{
if (pos.y <= surface - 10 * elapsed)
/*if (pos.y <= surface + 10 * elapsed)
{
double surfaceMomentum = (pos.y - surface) / elapsed;
if (surfaceMomentum < 0 && surfaceMomentum > -5)
if (surfaceMomentum < 0 && surfaceMomentum > 5)
{
// Stay on ground?
pos.y = surface;
momentum.y = 0;
}
}
else
{
onGround = false;
}
}*/
}

if (pos.y <= surface + FLOAT_EPSILON)
{
pos.y = surface;

if (!onGround)
{
playFallDownSound();
if (!firstUpdate)
{
crouchMomentum = min(crouchMomentum, momentum.y + 8);
}
momentum.y = 0;
//momentum.y = 0;
}
else
/*else
{
double surfaceMomentum = (surface - pos.y) / elapsed;
if (surfaceMomentum > 0)
{
// Push upward.
momentum.y = surfaceMomentum/20;
}
}
pos.y = surface;
}*/
//pos.y = surface;
momentum.y = 0;
onGround = true;
}
else
Expand Down

0 comments on commit e6c26fd

Please sign in to comment.