diff --git a/player/PlayerInteraction.gd b/player/PlayerInteraction.gd new file mode 100644 index 0000000..61510e1 --- /dev/null +++ b/player/PlayerInteraction.gd @@ -0,0 +1 @@ +extends Node diff --git a/player/PlayerInteraction.gd.uid b/player/PlayerInteraction.gd.uid new file mode 100644 index 0000000..e434ea5 --- /dev/null +++ b/player/PlayerInteraction.gd.uid @@ -0,0 +1 @@ +uid://b1ka4yih1ioh diff --git a/player/camera_rig.gd b/player/camera_rig.gd index f30da49..2e2105e 100644 --- a/player/camera_rig.gd +++ b/player/camera_rig.gd @@ -1,21 +1,30 @@ extends Node3D @export var target: Node3D + @export var follow_offset := Vector3(0, 10, 8) @export var follow_speed := 12.0 +@export var rotation_smooth_speed := 18.0 +@export var focus_smooth_speed := 14.0 + @export var mouse_sensitivity := 0.002 @export var deadzone_right := 3.0 @export var deadzone_forward := 3.0 var yaw := 0.0 +var smoothed_yaw := 0.0 + var focus_position := Vector3.ZERO +var desired_focus_position := Vector3.ZERO + func _ready() -> void: Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) if target: focus_position = target.global_position + desired_focus_position = focus_position global_position = focus_position + follow_offset @@ -31,28 +40,32 @@ func _physics_process(delta: float) -> void: if target == null: return - rotation = Vector3(deg_to_rad(-55), yaw, 0) + var rot_t := 1.0 - exp(-rotation_smooth_speed * delta) + var focus_t := 1.0 - exp(-focus_smooth_speed * delta) + var follow_t := 1.0 - exp(-follow_speed * delta) + + smoothed_yaw = lerp_angle(smoothed_yaw, yaw, rot_t) + + rotation = Vector3(deg_to_rad(-55), smoothed_yaw, 0) var target_pos := target.global_position - var diff := target_pos - focus_position + var diff := target_pos - desired_focus_position - # Camera-relative horizontal axes - var cam_right := Vector3.RIGHT.rotated(Vector3.UP, yaw).normalized() - var cam_forward := Vector3.FORWARD.rotated(Vector3.UP, yaw).normalized() + var cam_right := Vector3.RIGHT.rotated(Vector3.UP, smoothed_yaw).normalized() + var cam_forward := Vector3.FORWARD.rotated(Vector3.UP, smoothed_yaw).normalized() var diff_right := diff.dot(cam_right) var diff_forward := diff.dot(cam_forward) if abs(diff_right) > deadzone_right: - focus_position += cam_right * (diff_right - sign(diff_right) * deadzone_right) + desired_focus_position += cam_right * (diff_right - sign(diff_right) * deadzone_right) if abs(diff_forward) > deadzone_forward: - focus_position += cam_forward * (diff_forward - sign(diff_forward) * deadzone_forward) + desired_focus_position += cam_forward * (diff_forward - sign(diff_forward) * deadzone_forward) - var rotated_offset := follow_offset.rotated(Vector3.UP, yaw) + focus_position = focus_position.lerp(desired_focus_position, focus_t) + + var rotated_offset := follow_offset.rotated(Vector3.UP, smoothed_yaw) var desired_position := focus_position + rotated_offset - global_position = global_position.lerp( - desired_position, - 1.0 - exp(-follow_speed * delta) - ) + global_position = global_position.lerp(desired_position, follow_t) diff --git a/project.godot b/project.godot index f471b42..8af93bf 100644 --- a/project.godot +++ b/project.godot @@ -37,3 +37,8 @@ move_right={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null) ] } +Interaction={ +"deadzone": 0.2, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":69,"key_label":0,"unicode":101,"location":0,"echo":false,"script":null) +] +} diff --git a/simulation/SimulationManager.gd b/simulation/SimulationManager.gd index 11e9f72..8f3c9f5 100644 --- a/simulation/SimulationManager.gd +++ b/simulation/SimulationManager.gd @@ -78,3 +78,19 @@ func simulate_tick() -> void: village_changed.emit(village) if DEBUG_LOGS: print(village.get_summary()) + +func add_food(amount: float) -> void: + village.food += amount + village_changed.emit(village) + +func add_wood(amount: float) -> void: + village.wood += amount + village_changed.emit(village) + +func add_safety(amount: float) -> void: + village.safety = clamp(village.safety + amount, 0.0, 100.0) + village_changed.emit(village) + +func add_knowledge(amount: float) -> void: + village.knowledge += amount + village_changed.emit(village)