Skip to content

Instantly share code, notes, and snippets.

@kaeza

kaeza/gist:98fe97ae23db9572056a Secret

Last active Dec 19, 2015
Embed
What would you like to do?
Minetest: Change FOV based on player speed.
diff --git a/src/camera.cpp b/src/camera.cpp
index 3d8713d..f9ac800 100644
--- a/src/camera.cpp
+++ b/src/camera.cpp
@@ -354,7 +354,12 @@ void Camera::update(LocalPlayer* player, f32 frametime, v2u32 screensize,
m_cameranode->setTarget(m_camera_position + 100 * m_camera_direction);
// Get FOV setting
- f32 fov_degrees = g_settings->getFloat("fov");
+ f32 hyp;
+ {
+ v3f spd = player->getSpeed();
+ hyp = hypot(spd.X, spd.Z);
+ }
+ f32 fov_degrees = g_settings->getFloat("fov") + (hyp / 10);
fov_degrees = MYMAX(fov_degrees, 10.0);
fov_degrees = MYMIN(fov_degrees, 170.0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment