It's time for me to ask some questions here. The question is purely academic. I was making a simple all-round camera controller. I encountered a strange behavior. If you raise the camera as much as possible, it jams at the top. And it happens strictly in the height range from 1.564 to 1.746 (high_max). Of course, I invented a hack and rewrote it with a different approach, but I'm curious โ is there a materialistic explanation for this mysterious phenomenon?
Godot_v4.3-beta1
extends Node3D
@onready var tilt = $Camera_orbit
@onready var zoom = $Camera_orbit/Camera
@export var high_max := 1.62 # Jamming at 1.564 to 1.746. At these values, add "- 0.01" to line 42.
var high_min := 0.0
var SENSITIVITY := 0.01
func _unhandled_input(event: InputEvent) -> void:
# Mouse R-button press for rotation.
if event is InputEventMouseMotion and Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT):
tilt.rotation.y -= event.relative.x * SENSITIVITY
# Rotation clamp vertical.
tilt.rotation.x = clamp(tilt.rotation.x - event.relative.y * SENSITIVITY, -PI/2, PI/6)
# Zoom W-mouse.
elif event is InputEventMouseButton:
match event.button_index:
MOUSE_BUTTON_WHEEL_UP:
if event.is_pressed():
if zoom.position.z >= 0.3:
zoom.position.z -= 0.1
MOUSE_BUTTON_WHEEL_DOWN:
if event.is_pressed():
if zoom.position.z <= 2.0:
zoom.position.z += 0.1
# Mouse M-button change height.
elif event is InputEventMouseMotion and Input.is_mouse_button_pressed(MOUSE_BUTTON_MIDDLE):
# with jamming.
if tilt.position.y >= high_min and tilt.position.y <= high_max:
tilt.position.y += event.relative.y * SENSITIVITY
if tilt.position.y < high_min:
tilt.position.y = high_min
if tilt.position.y > high_max:
tilt.position.y = high_max# - 0.01
# w/o jamming.
#tilt.position.y += event.relative.y * SENSITIVITY
#tilt.position.y = clamp(tilt.position.y, high_min, high_max)
# Exit by ESC.
if event is InputEventKey:
if event.pressed and event.keycode == KEY_ESCAPE:
get_tree().quit()