101 lines
2.1 KiB
GDScript
101 lines
2.1 KiB
GDScript
extends CharacterBody3D
|
|
|
|
var nav_agent: NavigationAgent3D
|
|
|
|
var shirt_shader: ShaderMaterial
|
|
var meshI: MeshInstance3D
|
|
|
|
var start_pos: Vector3
|
|
var target_object: Node3D
|
|
|
|
var is_in_action: bool
|
|
var action: Interactable
|
|
|
|
var is_target_reached: bool
|
|
|
|
var timer: Timer
|
|
|
|
var is_holding_item: bool = false
|
|
var holdingItem: Object
|
|
|
|
|
|
var target_item: int
|
|
|
|
func _ready() -> void:
|
|
nav_agent = $NavigationAgent3D
|
|
meshI = $MeshInstance3D
|
|
shirt_shader = meshI.get_surface_override_material(1)
|
|
|
|
|
|
set_random_shirt()
|
|
|
|
start_pos = global_position
|
|
|
|
is_in_action = false
|
|
|
|
timer = $Timer
|
|
|
|
#nav_agent.target_position = Vector3(-15.955,3.486,-58.942)
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
var new_velocity = global_position.direction_to(nav_agent.get_next_path_position()) * 5.0
|
|
if !is_target_reached:
|
|
look_at(nav_agent.target_position)
|
|
velocity = new_velocity
|
|
move_and_slide()
|
|
|
|
func _input(event: InputEvent) -> void:
|
|
if event.is_action_pressed("test"):
|
|
ItemManager.set_person_target_item(self, "food")
|
|
#set_target_position()
|
|
|
|
|
|
|
|
|
|
func set_random_shirt():
|
|
var new_shirt_color = Vector3(randf(),randf(),randf())
|
|
shirt_shader.set_shader_parameter("shirt_color", new_shirt_color)
|
|
pass
|
|
|
|
|
|
func set_target(object):
|
|
|
|
#if !is_in_action and object.ActionNode.can_be_used():
|
|
if !is_in_action:
|
|
target_object = object
|
|
set_target_position()
|
|
#nav_agent.target_position = target_object.ActionNode.global_position
|
|
func set_target_position():
|
|
is_target_reached = false
|
|
var newPos = target_object.ActionNode.global_position
|
|
newPos.y = self.position.y
|
|
nav_agent.target_position = newPos
|
|
print(target_object.ActionNode.can_be_used())
|
|
|
|
#nav_agent.target_position = start_pos
|
|
|
|
|
|
func _on_navigation_agent_3d_target_reached() -> void:
|
|
if target_object != null:
|
|
is_target_reached = true
|
|
nav_agent.target_position = self.global_position
|
|
Global.interact.emit(self, target_object)
|
|
pass
|
|
|
|
|
|
func _on_timer_timeout() -> void:
|
|
if action != null:
|
|
print("action stoped")
|
|
action.stop_action(self,target_object)
|
|
|
|
|
|
func hold_item(item):
|
|
var newItem = item.instantiate()
|
|
holdingItem = newItem
|
|
newItem.position = Vector3(0,0.976, -0.065)
|
|
self.add_child(newItem)
|
|
|
|
|
|
func drop_item():
|
|
pass
|