plein de trucs dont des dialogues!
et ouai! appuye sur e pour parler au npc
This commit is contained in:
11
caracters/bob/bob.dialogue
Normal file
11
caracters/bob/bob.dialogue
Normal file
@@ -0,0 +1,11 @@
|
||||
~ start
|
||||
Nathan: [[Hi|Hello|Howdy]], this is some dialogue.
|
||||
Nathan: Here are some choices.
|
||||
- First one
|
||||
Nathan: You picked the first one.
|
||||
- Second one
|
||||
Nathan: You picked the second one.
|
||||
- Start again => start
|
||||
- End the conversation => END
|
||||
Nathan: For more information see the online documentation.
|
||||
=> END
|
||||
15
caracters/bob/bob.dialogue.import
Normal file
15
caracters/bob/bob.dialogue.import
Normal file
@@ -0,0 +1,15 @@
|
||||
[remap]
|
||||
|
||||
importer="dialogue_manager_compiler_14"
|
||||
type="Resource"
|
||||
uid="uid://vg4mssby1i6p"
|
||||
path="res://.godot/imported/bob.dialogue-14d9e78eeb4886b9f5556385117b67e2.tres"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://caracters/bob/bob.dialogue"
|
||||
dest_files=["res://.godot/imported/bob.dialogue-14d9e78eeb4886b9f5556385117b67e2.tres"]
|
||||
|
||||
[params]
|
||||
|
||||
defaults=true
|
||||
94
caracters/bob/bob.tscn
Normal file
94
caracters/bob/bob.tscn
Normal file
@@ -0,0 +1,94 @@
|
||||
[gd_scene load_steps=13 format=3 uid="uid://bleadp4yrdgj"]
|
||||
|
||||
[ext_resource type="Script" path="res://caracters/human.gd" id="1_x3vfc"]
|
||||
[ext_resource type="AnimationNodeStateMachine" uid="uid://ddr1ltkievtku" path="res://animations/human/human_state_machine.tres" id="2_86nrf"]
|
||||
[ext_resource type="PackedScene" uid="uid://bvsendl25xjju" path="res://animations/human/human_animation_player.tscn" id="3_lb4ws"]
|
||||
[ext_resource type="PackedScene" uid="uid://cg4dhp7qe68pt" path="res://animations/human/human.tscn" id="4_25owg"]
|
||||
[ext_resource type="Texture2D" uid="uid://c3lal83o1trpd" path="res://assest/persos/bob.png" id="5_e15yd"]
|
||||
[ext_resource type="PackedScene" uid="uid://brh7cqaxc13ie" path="res://zindex/ZIndexControler.tscn" id="5_g2w7l"]
|
||||
[ext_resource type="Script" path="res://caracters/npc.gd" id="7_xosjn"]
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_a4vmx"]
|
||||
radius = 5.0
|
||||
height = 48.0
|
||||
|
||||
[sub_resource type="AnimationNodeTimeScale" id="AnimationNodeTimeScale_85jde"]
|
||||
|
||||
[sub_resource type="AnimationNodeBlendTree" id="AnimationNodeBlendTree_iwsa7"]
|
||||
graph_offset = Vector2(0, -4)
|
||||
nodes/HumanState/node = ExtResource("2_86nrf")
|
||||
nodes/HumanState/position = Vector2(133.333, 120)
|
||||
nodes/TimeScale/node = SubResource("AnimationNodeTimeScale_85jde")
|
||||
nodes/TimeScale/position = Vector2(453.333, 53.3333)
|
||||
nodes/output/position = Vector2(640, 146.667)
|
||||
node_connections = [&"TimeScale", 0, &"HumanState", &"output", 0, &"TimeScale"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_1kv0e"]
|
||||
size = Vector2(40, 10)
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_6n4r3"]
|
||||
radius = 52.0
|
||||
height = 108.0
|
||||
|
||||
[node name="Bob" type="CharacterBody2D"]
|
||||
z_index = 100
|
||||
motion_mode = 1
|
||||
script = ExtResource("1_x3vfc")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
position = Vector2(0, 43)
|
||||
rotation = 1.5708
|
||||
shape = SubResource("CapsuleShape2D_a4vmx")
|
||||
|
||||
[node name="AnimationTree" type="AnimationTree" parent="."]
|
||||
tree_root = SubResource("AnimationNodeBlendTree_iwsa7")
|
||||
advance_expression_base_node = NodePath("..")
|
||||
anim_player = NodePath("../AnimationPlayer")
|
||||
parameters/HumanState/grabing/blend_position = Vector2(0, 0)
|
||||
parameters/HumanState/idling/blend_position = Vector2(0, 0)
|
||||
parameters/HumanState/walking/blend_position = Vector2(0, 0)
|
||||
parameters/TimeScale/scale = 1.0
|
||||
|
||||
[node name="AnimationPlayer" parent="." instance=ExtResource("3_lb4ws")]
|
||||
|
||||
[node name="Sprite2D" parent="." instance=ExtResource("4_25owg")]
|
||||
texture = ExtResource("5_e15yd")
|
||||
frame = 1
|
||||
|
||||
[node name="ZIndexControler" parent="." instance=ExtResource("5_g2w7l")]
|
||||
position = Vector2(-1, 37)
|
||||
|
||||
[node name="ShapeCast2D" type="ShapeCast2D" parent="ZIndexControler"]
|
||||
position = Vector2(1, -13)
|
||||
shape = SubResource("RectangleShape2D_1kv0e")
|
||||
target_position = Vector2(0, -48)
|
||||
|
||||
[node name="Area2D" type="Area2D" parent="."]
|
||||
collision_layer = 4
|
||||
collision_mask = 4
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
|
||||
position = Vector2(0, 43)
|
||||
rotation = 1.5708
|
||||
shape = SubResource("CapsuleShape2D_a4vmx")
|
||||
|
||||
[node name="npcControler" type="Node2D" parent="." node_paths=PackedStringArray("controled")]
|
||||
script = ExtResource("7_xosjn")
|
||||
controled = NodePath("..")
|
||||
|
||||
[node name="Label" type="Label" parent="npcControler"]
|
||||
visible = false
|
||||
offset_right = 40.0
|
||||
offset_bottom = 23.0
|
||||
|
||||
[node name="interactable" type="Area2D" parent="."]
|
||||
collision_layer = 8
|
||||
collision_mask = 8
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="interactable"]
|
||||
position = Vector2(0, 12)
|
||||
shape = SubResource("CapsuleShape2D_6n4r3")
|
||||
|
||||
[connection signal="start_intracting" from="." to="npcControler" method="_on_character_body_2d_start_intracting"]
|
||||
[connection signal="area_entered" from="Area2D" to="." method="_on_area_2d_area_entered"]
|
||||
[connection signal="body_entered" from="Area2D" to="." method="_on_area_2d_body_entered"]
|
||||
93
caracters/bob/bob76A8.tmp
Normal file
93
caracters/bob/bob76A8.tmp
Normal file
@@ -0,0 +1,93 @@
|
||||
[gd_scene load_steps=13 format=3 uid="uid://bleadp4yrdgj"]
|
||||
|
||||
[ext_resource type="Script" path="res://caracters/human.gd" id="1_x3vfc"]
|
||||
[ext_resource type="AnimationNodeStateMachine" uid="uid://ddr1ltkievtku" path="res://animations/human/human_state_machine.tres" id="2_86nrf"]
|
||||
[ext_resource type="PackedScene" uid="uid://bvsendl25xjju" path="res://animations/human/human_animation_player.tscn" id="3_lb4ws"]
|
||||
[ext_resource type="PackedScene" uid="uid://cg4dhp7qe68pt" path="res://animations/human/human.tscn" id="4_25owg"]
|
||||
[ext_resource type="Texture2D" uid="uid://c3lal83o1trpd" path="res://assest/persos/bob.png" id="5_e15yd"]
|
||||
[ext_resource type="PackedScene" uid="uid://brh7cqaxc13ie" path="res://zindex/ZIndexControler.tscn" id="5_g2w7l"]
|
||||
[ext_resource type="Script" path="res://caracters/npc.gd" id="7_xosjn"]
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_a4vmx"]
|
||||
radius = 5.0
|
||||
height = 48.0
|
||||
|
||||
[sub_resource type="AnimationNodeTimeScale" id="AnimationNodeTimeScale_85jde"]
|
||||
|
||||
[sub_resource type="AnimationNodeBlendTree" id="AnimationNodeBlendTree_iwsa7"]
|
||||
graph_offset = Vector2(0, -4)
|
||||
nodes/HumanState/node = ExtResource("2_86nrf")
|
||||
nodes/HumanState/position = Vector2(133.333, 120)
|
||||
nodes/TimeScale/node = SubResource("AnimationNodeTimeScale_85jde")
|
||||
nodes/TimeScale/position = Vector2(453.333, 53.3333)
|
||||
nodes/output/position = Vector2(640, 146.667)
|
||||
node_connections = [&"TimeScale", 0, &"HumanState", &"output", 0, &"TimeScale"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_1kv0e"]
|
||||
size = Vector2(40, 10)
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_6n4r3"]
|
||||
radius = 52.0
|
||||
height = 108.0
|
||||
|
||||
[node name="Bob" type="CharacterBody2D"]
|
||||
z_index = 100
|
||||
motion_mode = 1
|
||||
script = ExtResource("1_x3vfc")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
position = Vector2(0, 43)
|
||||
rotation = 1.5708
|
||||
shape = SubResource("CapsuleShape2D_a4vmx")
|
||||
|
||||
[node name="AnimationTree" type="AnimationTree" parent="."]
|
||||
tree_root = SubResource("AnimationNodeBlendTree_iwsa7")
|
||||
advance_expression_base_node = NodePath("..")
|
||||
anim_player = NodePath("../AnimationPlayer")
|
||||
parameters/HumanState/grabing/blend_position = Vector2(0, 0)
|
||||
parameters/HumanState/idling/blend_position = Vector2(0, 0)
|
||||
parameters/HumanState/walking/blend_position = Vector2(0, 0)
|
||||
parameters/TimeScale/scale = 1.0
|
||||
|
||||
[node name="AnimationPlayer" parent="." instance=ExtResource("3_lb4ws")]
|
||||
|
||||
[node name="Sprite2D" parent="." instance=ExtResource("4_25owg")]
|
||||
texture = ExtResource("5_e15yd")
|
||||
frame = 1
|
||||
|
||||
[node name="ZIndexControler" parent="." instance=ExtResource("5_g2w7l")]
|
||||
position = Vector2(-1, 37)
|
||||
|
||||
[node name="ShapeCast2D" type="ShapeCast2D" parent="ZIndexControler"]
|
||||
position = Vector2(1, -13)
|
||||
shape = SubResource("RectangleShape2D_1kv0e")
|
||||
target_position = Vector2(0, -48)
|
||||
|
||||
[node name="Area2D" type="Area2D" parent="."]
|
||||
collision_layer = 4
|
||||
collision_mask = 4
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
|
||||
position = Vector2(0, 43)
|
||||
rotation = 1.5708
|
||||
shape = SubResource("CapsuleShape2D_a4vmx")
|
||||
|
||||
[node name="npcControler" type="Node2D" parent="." node_paths=PackedStringArray("controled")]
|
||||
script = ExtResource("7_xosjn")
|
||||
controled = NodePath("..")
|
||||
|
||||
[node name="Label" type="Label" parent="npcControler"]
|
||||
offset_right = 40.0
|
||||
offset_bottom = 23.0
|
||||
|
||||
[node name="interactable" type="Area2D" parent="."]
|
||||
collision_layer = 8
|
||||
collision_mask = 8
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="interactable"]
|
||||
position = Vector2(0, 12)
|
||||
shape = SubResource("CapsuleShape2D_6n4r3")
|
||||
|
||||
[connection signal="start_intracting" from="." to="npcControler" method="_on_character_body_2d_start_intracting"]
|
||||
[connection signal="area_entered" from="Area2D" to="." method="_on_area_2d_area_entered"]
|
||||
[connection signal="body_entered" from="Area2D" to="." method="_on_area_2d_body_entered"]
|
||||
5
caracters/bob/interactable.gd
Normal file
5
caracters/bob/interactable.gd
Normal file
@@ -0,0 +1,5 @@
|
||||
extends Area2D
|
||||
|
||||
|
||||
func start_interaction(askingForInteraction: Human):
|
||||
(get_parent() as Human).start_interaction(askingForInteraction)
|
||||
75
caracters/human.gd
Normal file
75
caracters/human.gd
Normal file
@@ -0,0 +1,75 @@
|
||||
class_name Human
|
||||
extends CharacterBody2D
|
||||
|
||||
@export var speed = 250 # How fast the player will move (pixels/sec).
|
||||
|
||||
# intensions of the player turner into a boolean
|
||||
@export var wants_to_grab = false;
|
||||
var wants_to_interact_with: Node2D
|
||||
var humanInteractionTarget: Human = null
|
||||
|
||||
@onready var animation_tree := $AnimationTree
|
||||
@onready var animation_player := $AnimationPlayer
|
||||
@onready var state_machine := animation_tree.get("parameters/HumanState/playback") as AnimationNodeStateMachinePlayback
|
||||
|
||||
signal start_intracting
|
||||
|
||||
var last_facing_direction = Vector2(0,1) # facing south
|
||||
var velocityVector = Vector2(0, 0)
|
||||
var targetGlobalPosition = null
|
||||
|
||||
func moveTo(p: Vector2) -> void:
|
||||
targetGlobalPosition = p
|
||||
|
||||
func moveFeetTo(p: Vector2) -> void:
|
||||
targetGlobalPosition = p - Vector2(0, 43)
|
||||
|
||||
func face(whereToFace: Vector2) -> void:
|
||||
last_facing_direction = (whereToFace - global_position).normalized()
|
||||
|
||||
func decideAction() -> void:
|
||||
pass
|
||||
|
||||
func updateFacingDirectionInAnimationTree():
|
||||
animation_tree.set("parameters/HumanState/grabing/blend_position", last_facing_direction)
|
||||
animation_tree.set("parameters/HumanState/idling/blend_position", last_facing_direction)
|
||||
animation_tree.set("parameters/HumanState/walking/blend_position", last_facing_direction)
|
||||
|
||||
func _physics_process(delta):
|
||||
decideAction()
|
||||
|
||||
if (targetGlobalPosition != null):
|
||||
velocity = (targetGlobalPosition - global_position).normalized() *speed
|
||||
targetGlobalPosition = null
|
||||
else:
|
||||
velocity = velocityVector * speed
|
||||
|
||||
if state_machine.get_current_node() == "grabing":
|
||||
velocity = Vector2(0,0);
|
||||
|
||||
# move the caracter
|
||||
move_and_slide()
|
||||
|
||||
# compute the direction the player wants to look at
|
||||
if velocity:
|
||||
last_facing_direction = velocity.normalized()
|
||||
stop_interaction()
|
||||
|
||||
updateFacingDirectionInAnimationTree()
|
||||
|
||||
if wants_to_interact_with and wants_to_interact_with.get_parent().has_method("start_interaction"):
|
||||
if humanInteractionTarget == null:
|
||||
humanInteractionTarget = wants_to_interact_with.get_parent() as Human
|
||||
humanInteractionTarget.start_interaction(self)
|
||||
|
||||
func _on_area_2d_body_entered(body: Node2D) -> void:
|
||||
print(body)
|
||||
|
||||
func start_interaction(askingForInteraction: Human):
|
||||
emit_signal("start_intracting", askingForInteraction)
|
||||
|
||||
func stop_interaction():
|
||||
humanInteractionTarget = null
|
||||
|
||||
func get_feet_global_position():
|
||||
return global_position + Vector2(0, 43)
|
||||
73
caracters/npc.gd
Normal file
73
caracters/npc.gd
Normal file
@@ -0,0 +1,73 @@
|
||||
extends Node
|
||||
|
||||
var astar_grid: AStarGrid2D
|
||||
var toFollow: Array[Vector2i]
|
||||
@onready var world: TileMapLayer = get_parent().get_parent();
|
||||
@onready var obstacles: TileMapLayer = world.get_children()[2]
|
||||
|
||||
@export var controled:Human
|
||||
var destination:Node2D
|
||||
var HumanLayer = 0
|
||||
|
||||
func _ready() -> void:
|
||||
astar_grid = AStarGrid2D.new()
|
||||
astar_grid.region = world.get_used_rect()
|
||||
astar_grid.cell_size = Vector2(48, 48)
|
||||
astar_grid.diagonal_mode = AStarGrid2D.DIAGONAL_MODE_NEVER
|
||||
astar_grid.default_compute_heuristic = AStarGrid2D.HEURISTIC_EUCLIDEAN
|
||||
astar_grid.default_estimate_heuristic = AStarGrid2D.HEURISTIC_EUCLIDEAN
|
||||
astar_grid.update()
|
||||
|
||||
# only take into account the tiles that are marked with a navigation layer for cars
|
||||
for x in world.get_used_rect().size.x:
|
||||
for y in world.get_used_rect().size.y:
|
||||
var tile_position = Vector2(
|
||||
x + world.get_used_rect().position.x,
|
||||
y + world.get_used_rect().position.y,
|
||||
)
|
||||
var tile_data = world.get_cell_tile_data(tile_position)
|
||||
if tile_data == null or tile_data.get_navigation_polygon(HumanLayer) == null:
|
||||
astar_grid.set_point_solid(tile_position)
|
||||
|
||||
if obstacles.get_cell_tile_data(tile_position) != null and obstacles.get_cell_tile_data(tile_position).get_collision_polygons_count(0):
|
||||
astar_grid.set_point_solid(tile_position)
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if !controled:
|
||||
return
|
||||
if destination:
|
||||
var my_global_position = controled.get_feet_global_position()
|
||||
var target_global_position = destination.get_feet_global_position()
|
||||
|
||||
# make the wanted position on the track move ahead by a certain amount
|
||||
#if toFollow == null or toFollow.is_empty():
|
||||
# compute the new navigation points the car should follow
|
||||
var points = astar_grid.get_id_path(
|
||||
world.local_to_map(world.to_local(my_global_position)),
|
||||
world.local_to_map(world.to_local(target_global_position))
|
||||
).slice(1, -1)
|
||||
if !points.is_empty():
|
||||
toFollow = points
|
||||
|
||||
if $Label.visible:
|
||||
$Label.text = (
|
||||
"position "+str(world.local_to_map(world.to_local(my_global_position)))+" , "+str(my_global_position)+
|
||||
"\ntarget position "+ str(world.local_to_map(world.to_local(target_global_position)))+" , "+str(target_global_position)+
|
||||
"\npoint to follow "+str(toFollow)
|
||||
)
|
||||
|
||||
if !toFollow.is_empty():
|
||||
if world.local_to_map(world.to_local(my_global_position)) == toFollow.front():
|
||||
toFollow.pop_front()
|
||||
|
||||
if !toFollow.is_empty():
|
||||
controled.moveFeetTo(world.to_global(world.map_to_local(toFollow.front())));
|
||||
else:
|
||||
controled.face(target_global_position)
|
||||
|
||||
func _on_character_body_2d_start_intracting(interactingWith: Human) -> void:
|
||||
controled.face(interactingWith.global_position)
|
||||
print("pouet")
|
||||
# ouvre un dialogue
|
||||
var resource = load("res://caracters/bob/bob.dialogue")
|
||||
DialogueManager.show_dialogue_balloon(resource, "start")
|
||||
@@ -1,5 +1,6 @@
|
||||
[gd_scene load_steps=10 format=3 uid="uid://vclpg4e4ql54"]
|
||||
[gd_scene load_steps=12 format=3 uid="uid://vclpg4e4ql54"]
|
||||
|
||||
[ext_resource type="Script" path="res://caracters/human.gd" id="1_l1sti"]
|
||||
[ext_resource type="Script" path="res://caracters/player/player_controler.gd" id="1_oapm5"]
|
||||
[ext_resource type="AnimationNodeStateMachine" uid="uid://ddr1ltkievtku" path="res://animations/human/human_state_machine.tres" id="3_1y7fn"]
|
||||
[ext_resource type="PackedScene" uid="uid://bvsendl25xjju" path="res://animations/human/human_animation_player.tscn" id="3_c286j"]
|
||||
@@ -23,12 +24,18 @@ node_connections = [&"TimeScale", 0, &"HumanState", &"output", 0, &"TimeScale"]
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_1kv0e"]
|
||||
size = Vector2(40, 10)
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_11ib5"]
|
||||
size = Vector2(20, 150)
|
||||
|
||||
[node name="CharacterBody2D" type="CharacterBody2D"]
|
||||
z_index = 100
|
||||
motion_mode = 1
|
||||
script = ExtResource("1_oapm5")
|
||||
script = ExtResource("1_l1sti")
|
||||
metadata/_edit_vertical_guides_ = [-20.0]
|
||||
metadata/_edit_horizontal_guides_ = [48.0]
|
||||
|
||||
[node name="Camera2D" type="Camera2D" parent="."]
|
||||
zoom = Vector2(1.5, 1.5)
|
||||
position_smoothing_enabled = true
|
||||
drag_horizontal_enabled = true
|
||||
drag_vertical_enabled = true
|
||||
@@ -43,7 +50,7 @@ tree_root = SubResource("AnimationNodeBlendTree_iwsa7")
|
||||
advance_expression_base_node = NodePath("..")
|
||||
anim_player = NodePath("../AnimationPlayer")
|
||||
parameters/HumanState/grabing/blend_position = Vector2(0, 0)
|
||||
parameters/HumanState/idling/blend_position = Vector2(0, 0)
|
||||
parameters/HumanState/idling/blend_position = Vector2(0.000657439, 1.0284)
|
||||
parameters/HumanState/walking/blend_position = Vector2(0, 0)
|
||||
parameters/TimeScale/scale = 1.0
|
||||
|
||||
@@ -69,5 +76,17 @@ position = Vector2(0, 43)
|
||||
rotation = 1.5708
|
||||
shape = SubResource("CapsuleShape2D_a4vmx")
|
||||
|
||||
[node name="controleur" type="Node2D" parent="." node_paths=PackedStringArray("human", "ray")]
|
||||
script = ExtResource("1_oapm5")
|
||||
human = NodePath("..")
|
||||
ray = NodePath("../ShapeCast2D")
|
||||
|
||||
[node name="ShapeCast2D" type="ShapeCast2D" parent="."]
|
||||
shape = SubResource("RectangleShape2D_11ib5")
|
||||
target_position = Vector2(1, 90)
|
||||
collision_mask = 8
|
||||
collide_with_areas = true
|
||||
collide_with_bodies = false
|
||||
|
||||
[connection signal="area_entered" from="Area2D" to="." method="_on_area_2d_area_entered"]
|
||||
[connection signal="body_entered" from="Area2D" to="." method="_on_area_2d_body_entered"]
|
||||
|
||||
@@ -1,39 +1,47 @@
|
||||
class_name PlayerControler
|
||||
extends CharacterBody2D
|
||||
extends Node
|
||||
|
||||
@export var speed = 250 # How fast the player will move (pixels/sec).
|
||||
@export var human: Human
|
||||
@export var ray : ShapeCast2D
|
||||
var interactable : Node2D
|
||||
|
||||
# intensions of the player turner into a boolean
|
||||
@export var wants_to_grab = false;
|
||||
|
||||
@onready var animation_tree := $AnimationTree
|
||||
@onready var state_machine := animation_tree.get("parameters/HumanState/playback") as AnimationNodeStateMachinePlayback
|
||||
|
||||
var last_facing_direction = Vector2(0,-1) # facing south
|
||||
|
||||
func readInputs():
|
||||
wants_to_grab = Input.is_action_pressed("grab");
|
||||
if state_machine.get_current_node() == "grabing":
|
||||
velocity = Vector2(0,0);
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if (
|
||||
event.is_action("move_left") or
|
||||
event.is_action("move_right") or
|
||||
event.is_action("move_up") or
|
||||
event.is_action("move_down")
|
||||
):
|
||||
human.velocityVector = Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||||
if event.is_action_pressed("grab"):
|
||||
if interactable:
|
||||
human.stop_interaction()
|
||||
human.wants_to_interact_with = interactable
|
||||
else:
|
||||
human.wants_to_grab = true
|
||||
else:
|
||||
velocity = Input.get_vector("move_left", "move_right", "move_up", "move_down") * speed
|
||||
human.wants_to_grab = false
|
||||
human.wants_to_interact_with = null
|
||||
|
||||
func updateFacingDirectionInAnimationTree():
|
||||
animation_tree.set("parameters/HumanState/grabing/blend_position", last_facing_direction)
|
||||
animation_tree.set("parameters/HumanState/idling/blend_position", last_facing_direction)
|
||||
animation_tree.set("parameters/HumanState/walking/blend_position", last_facing_direction)
|
||||
func _process(delta) -> void:
|
||||
ray.target_position = human.last_facing_direction * 48
|
||||
|
||||
func _physics_process(delta):
|
||||
readInputs()
|
||||
if human.last_facing_direction.y > 0 :
|
||||
ray.target_position = Vector2(0, 48)
|
||||
(ray.shape as RectangleShape2D).size = Vector2(50, 20)
|
||||
elif human.last_facing_direction.y < 0:
|
||||
ray.target_position = Vector2(0, -48)
|
||||
(ray.shape as RectangleShape2D).size = Vector2(50, 20)
|
||||
elif human.last_facing_direction.x > 0 :
|
||||
ray.target_position = Vector2(48, 0)
|
||||
(ray.shape as RectangleShape2D).size = Vector2(20, 50)
|
||||
else:
|
||||
ray.target_position = Vector2(-48, 0)
|
||||
(ray.shape as RectangleShape2D).size = Vector2(20, 50)
|
||||
|
||||
# move the caracter
|
||||
move_and_slide()
|
||||
|
||||
# compute the direction the player wants to look at
|
||||
if velocity:
|
||||
last_facing_direction = velocity.normalized()
|
||||
|
||||
updateFacingDirectionInAnimationTree()
|
||||
|
||||
func _on_area_2d_body_entered(body: Node2D) -> void:
|
||||
print(body)
|
||||
interactable = null
|
||||
if ray.is_colliding():
|
||||
var nbCollisions = ray.get_collision_count()
|
||||
for n in range(nbCollisions):
|
||||
var colider = ray.get_collider(n) as Node2D
|
||||
if colider != null and colider != get_parent():
|
||||
interactable = colider
|
||||
|
||||
Reference in New Issue
Block a user