Skip to content

Commit

Permalink
[Forest] Fixed an issue where when looking up or down with the physic…
Browse files Browse the repository at this point in the history
…s based camera, movement would come to a stop
  • Loading branch information
PanosK92 committed Nov 21, 2023
1 parent 7c297f0 commit 9964ab7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
7 changes: 3 additions & 4 deletions data/shaders/common_vertex_simulation.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,16 @@ struct vertex_simulation
static const float ripple_decay_rate = 0.1f;
static const float ripple_decay_after_movement = 2.0f; // Time for ripples to decay after movement stops

// Calculate time since the player last moved
// calculate time since the player last moved
float time_since_last_movement = time - buffer_frame.camera_last_movement_time;

// Check if the camera (player) is near the water level
// check if the camera (player) is near the water level
if (abs(buffer_frame.camera_position.y - buffer_frame.water_level) < 4.0f)
{
float distance = length(position_vertex.xz - buffer_frame.camera_position.xz);
float ripple_phase = time * ripple_speed - ripple_frequency * distance;

// Adjust the ripple height based on time since last movement
// adjust the ripple height based on time since last movement
float decay_factor = max(1.0f - (time_since_last_movement / ripple_decay_after_movement), 0.0f);
float ripple_height = ripple_max_height * sin(ripple_phase) * exp(-ripple_decay_rate * distance) * decay_factor;

Expand All @@ -172,6 +172,5 @@ struct vertex_simulation

return position_vertex;
}

};
};
13 changes: 11 additions & 2 deletions runtime/World/Components/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,15 @@ namespace Spartan
if (Input::GetKey(KeyCode::A)) movement_direction += GetTransform()->GetLeft();
if (Input::GetKey(KeyCode::Q)) movement_direction += GetTransform()->GetDown();
if (Input::GetKey(KeyCode::E)) movement_direction += GetTransform()->GetUp();

// when in game mode and controlling a physics based camera ignore the pitch
// this is so the view direction (forward) is never pointing towards the ground or sky
// cause movement to come a stop
if (m_physics_body_to_control && Engine::IsFlagSet(EngineMode::Game))
{
movement_direction.y = 0.0f;
}

movement_direction.Normalize();
}

Expand Down Expand Up @@ -555,7 +564,7 @@ namespace Spartan
FocusOnSelectedEntity();
}

// Set bookmark as a lerp target
// set bookmark as a lerp target
bool lerp_to_bookmark = false;
if (lerp_to_bookmark = m_lerpt_to_bookmark && m_target_bookmark_index >= 0 && m_target_bookmark_index < m_bookmarks.size())
{
Expand All @@ -569,7 +578,7 @@ namespace Spartan
m_lerpt_to_bookmark = false;
}

// Lerp
// lerp
if (m_lerp_to_target_p || m_lerp_to_target_r || lerp_to_bookmark)
{
// Lerp duration in seconds
Expand Down

0 comments on commit 9964ab7

Please sign in to comment.