From 811d5bf064ce992bc742f55c112a777801126861 Mon Sep 17 00:00:00 2001 From: nathan Date: Sun, 6 Jul 2025 15:38:08 -0600 Subject: Finally smooth walking --- src/player.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/player.c') diff --git a/src/player.c b/src/player.c index 0342040..9c66627 100644 --- a/src/player.c +++ b/src/player.c @@ -18,6 +18,14 @@ Player createPlayer() }; } +// Fake physics, distance from ground. +void updatePlayerHeight(Player* player, Game* game) +{ + float height = getWorldHeightAtLocation( + game->world, player->position.x, player->position.z) + PLAYER_HEIGHT; + player->position.y = height; +} + // TODO: move magic numbers to settings void updatePlayer(Player* player, Game* game) { @@ -65,14 +73,13 @@ void updatePlayer(Player* player, Game* game) player->velocity = Vector3Scale(player->velocity, 10.0); - // Apply velocity + // Apply velocity. player->position = Vector3Add( player->position, Vector3Scale(player->velocity, GetFrameTime())); + + updatePlayerHeight(player, game); // Apply camera. camera->position = player->position; camera->target = Vector3Add(player->position, player->direction); - - player->position.y = getWorldHeightAtLocation( - game->world, player->position.x, player->position.z) + PLAYER_HEIGHT; } -- cgit v1.2.3