feat: add user interaction with the task zones
This commit is contained in:
@@ -5,6 +5,17 @@ extends CharacterBody3D
|
||||
@export var rotation_speed := 12.0
|
||||
@export var camera_rig: Node3D
|
||||
|
||||
@export var simulation_manager: Node
|
||||
|
||||
@export var farm_zone: Marker3D
|
||||
@export var forest_zone: Marker3D
|
||||
@export var food_zone: Marker3D
|
||||
@export var guard_zone: Marker3D
|
||||
@export var study_zone: Marker3D
|
||||
|
||||
@export var stomach_capacity_for_food := 5
|
||||
@export var interaction_range := 3.0
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
var input := Input.get_vector(
|
||||
"move_left",
|
||||
@@ -39,3 +50,36 @@ func _physics_process(delta: float) -> void:
|
||||
if direction.length() > 0.01:
|
||||
var target_angle := atan2(direction.x, direction.z)
|
||||
rotation.y = lerp_angle(rotation.y, target_angle, rotation_speed * delta)
|
||||
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
# keep your camera mouse code here too
|
||||
if event.is_action_pressed("interact"):
|
||||
try_interact()
|
||||
|
||||
|
||||
func try_interact() -> void:
|
||||
if simulation_manager == null:
|
||||
return
|
||||
|
||||
if is_near(farm_zone):
|
||||
simulation_manager.add_food(5.0)
|
||||
print("Player gathered food for the village.")
|
||||
elif is_near(forest_zone):
|
||||
simulation_manager.add_wood(5.0)
|
||||
print("Player gathered wood for the village.")
|
||||
elif is_near(guard_zone):
|
||||
simulation_manager.add_safety(3.0)
|
||||
print("Player helped guard the village.")
|
||||
elif is_near(study_zone):
|
||||
simulation_manager.add_knowledge(2.0)
|
||||
print("Player shared knowledge.")
|
||||
elif is_near(food_zone):
|
||||
simulation_manager.eat_food(stomach_capacity_for_food)
|
||||
print("Player eating shit up.")
|
||||
|
||||
func is_near(zone: Marker3D) -> bool:
|
||||
if zone == null:
|
||||
return false
|
||||
|
||||
return global_position.distance_to(zone.global_position) <= interaction_range
|
||||
|
||||
Reference in New Issue
Block a user