plein de trucs dont des dialogues!
et ouai! appuye sur e pour parler au npc
This commit is contained in:
@@ -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