Le z-indexeur est là pour z-indexer tous ces petits gars

Quand il rentre en action il trouve si quelqu'un est en collision
Et il prend la hauteur de cette personne et se place au dessus
Il est comme ça le zindexeur, il est sans gêne
This commit is contained in:
Thomas
2025-02-22 09:21:28 +01:00
parent ec29c50631
commit 5721680834
9 changed files with 128 additions and 58 deletions

File diff suppressed because one or more lines are too long

View File

@@ -1,9 +1,10 @@
[gd_scene load_steps=8 format=3 uid="uid://vclpg4e4ql54"]
[gd_scene load_steps=10 format=3 uid="uid://vclpg4e4ql54"]
[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"]
[ext_resource type="PackedScene" uid="uid://cg4dhp7qe68pt" path="res://animations/human/human.tscn" id="4_rsj36"]
[ext_resource type="PackedScene" uid="uid://brh7cqaxc13ie" path="res://zindex/ZIndexControler.tscn" id="5_pb07x"]
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_a4vmx"]
radius = 5.0
@@ -20,6 +21,9 @@ 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)
[node name="CharacterBody2D" type="CharacterBody2D"]
z_index = 100
motion_mode = 1
@@ -49,3 +53,11 @@ parameters/TimeScale/scale = 1.55
[node name="Sprite2D" parent="." instance=ExtResource("4_rsj36")]
frame = 1
[node name="ZIndexControler" parent="." instance=ExtResource("5_pb07x")]
position = Vector2(-1, 37)
[node name="ShapeCast2D" type="ShapeCast2D" parent="ZIndexControler"]
position = Vector2(1, -13)
shape = SubResource("RectangleShape2D_1kv0e")
target_position = Vector2(0, -48)

File diff suppressed because one or more lines are too long

View File

@@ -8,6 +8,8 @@ extends PathFollow2D
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
if position.distance_to(car.position) < 200:
progress_ratio += delta * speed;
if position.distance_to(car.position) < distanceMax:
progress += car.speed * delta
if progress_ratio > 1:
progress_ratio = progress_ratio - 1
car.moveTo(position);

View File

@@ -13,9 +13,9 @@ point_count = 15
[sub_resource type="Curve2D" id="Curve2D_nircx"]
_data = {
"points": PackedVector2Array(0, 0, 0, 0, 803, 1569, 0, 0, 0, 0, 910, 1573, 0, 0, 0, 0, 913, 1368, 0, 0, 0, 0, 1926, 1371, 0, 0, 0, 0, 1931, 342, 0, 0, 0, 0, 2082, 333, 0, 0, 0, 0, 2060, -140, 0, 0, 0, 0, 1718, -143, 0, 0, 0, 0, 1649, 73, 0, 0, 0, 0, 814, 68, 0, 0, 0, 0, 897, -123, 0, 0, 0, 0, 904, -1165, 0, 0, 0, 0, -890, -1162, 0, 0, 0, 0, -886, -119, 0, 0, 0, 0, -1062, -106, 0, 0, 0, 0, -1076, 268, 0, 0, 0, 0, -630, 271, 0, 0, 0, 0, -616, 161, 0, 0, 0, 0, 858, 167, 0, 0, 0, 0, 806, 1560)
"points": PackedVector2Array(0, 0, 0, 0, 803, 1569, 0, 0, 0, 0, 910, 1573, 0, 0, 0, 0, 913, 1368, 0, 0, 0, 0, 1926, 1371, 0, 0, 0, 0, 1931, 342, 0, 0, 0, 0, 2082, 333, 0, 0, 0, 0, 2060, -140, 0, 0, 0, 0, 1718, -143, 0, 0, 0, 0, 1649, 73, 0, 0, 0, 0, 899, 51, 0, 0, 0, 0, 904, -1165, 0, 0, 0, 0, -890, -1162, 0, 0, 0, 0, -886, -119, 0, 0, 0, 0, -1062, -106, 0, 0, 0, 0, -1076, 268, 0, 0, 0, 0, -630, 271, 0, 0, 0, 0, -616, 161, 0, 0, 0, 0, 858, 167, 0, 0, 0, 0, 806, 1560)
}
point_count = 20
point_count = 19
[node name="scene1" type="Node2D"]
@@ -23,7 +23,7 @@ point_count = 20
[node name="movibles" type="Node2D" parent="."]
[node name="Area2D" parent="movibles" instance=ExtResource("2_5x6b5")]
[node name="player" parent="movibles" instance=ExtResource("2_5x6b5")]
position = Vector2(87, 74)
[node name="voitures" type="Node" parent="movibles"]
@@ -48,8 +48,14 @@ curve = SubResource("Curve2D_nircx")
[node name="voiture_pnj" parent="movibles/voitures/Path2D2" node_paths=PackedStringArray("car") instance=ExtResource("3_yuakw")]
position = Vector2(803, 1569)
car = NodePath("../Car")
distanceMax = 15
speed = 0.1
distanceMax = 150
[node name="Label" type="Label" parent="movibles/voitures/Path2D2/voiture_pnj"]
offset_right = 40.0
offset_bottom = 23.0
text = "LAPIN"
[node name="Car" parent="movibles/voitures/Path2D2" instance=ExtResource("4_bqm78")]
position = Vector2(803, 1558)
speed = 500
speed = 400

View File

@@ -1,6 +1,7 @@
class_name Car
extends CharacterBody2D
@export var debugLabel: Label
@export var speed = 750 # How fast the car will move (pixels/sec).
@onready var animation_tree := $AnimationTree
@onready var state_machine := animation_tree.get("parameters/driving/playback") as AnimationNodeStateMachinePlayback
@@ -18,8 +19,11 @@ func updateFacingDirectionInAnimationTree():
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
$ZIndexControler/ShapeCast2D.enabled = !$CollisionHorizontal.disabled
if (targetPosition != null):
velocity = (targetPosition - position) * speed * delta;
move_and_slide()
if velocity:
last_facing_direction = velocity.normalized()

View File

@@ -1,6 +1,7 @@
[gd_scene load_steps=33 format=3 uid="uid://bt1p311rn1h6q"]
[gd_scene load_steps=35 format=3 uid="uid://bt1p311rn1h6q"]
[ext_resource type="Script" path="res://vehicules/car.gd" id="1_vkq5y"]
[ext_resource type="PackedScene" uid="uid://brh7cqaxc13ie" path="res://zindex/ZIndexControler.tscn" id="3_iaqxo"]
[ext_resource type="Texture2D" uid="uid://dq81e78eaild8" path="res://assest/vehicules/Car_classic_red_48x48.png" id="4_0kman"]
[sub_resource type="Animation" id="Animation_24r8n"]
@@ -329,6 +330,47 @@ tracks/2/keys = {
"values": [true]
}
[sub_resource type="Animation" id="Animation_xch04"]
resource_name = "idling_up"
length = 0.1
loop_mode = 1
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Car/Sprite2D:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [35]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("Car/CollisionHorizontal:disabled")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [true]
}
tracks/2/type = "value"
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/path = NodePath("Car/CollisionVertical:disabled")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [false]
}
[sub_resource type="Animation" id="Animation_0uy2s"]
resource_name = "opening_door_left"
tracks/0/type = "value"
@@ -407,47 +449,6 @@ tracks/2/keys = {
"values": [true]
}
[sub_resource type="Animation" id="Animation_xch04"]
resource_name = "idling_up"
length = 0.1
loop_mode = 1
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Car/Sprite2D:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [35]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("Car/CollisionHorizontal:disabled")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [true]
}
tracks/2/type = "value"
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/path = NodePath("Car/CollisionVertical:disabled")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [false]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_10pc8"]
_data = {
"RESET": SubResource("Animation_24r8n"),
@@ -537,7 +538,7 @@ graph_offset = Vector2(80, -182)
[sub_resource type="AnimationNodeTimeScale" id="AnimationNodeTimeScale_5fwej"]
[sub_resource type="AnimationNodeBlendTree" id="AnimationNodeBlendTree_q5j17"]
graph_offset = Vector2(-249.333, -55.3333)
graph_offset = Vector2(-221.333, -11.3333)
nodes/CarStates/node = SubResource("AnimationNodeStateMachine_tnex5")
nodes/CarStates/position = Vector2(-133.333, 173.333)
nodes/TimeScale/node = SubResource("AnimationNodeTimeScale_5fwej")
@@ -546,11 +547,15 @@ node_connections = [&"TimeScale", 0, &"CarStates", &"output", 0, &"TimeScale"]
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_l8rwt"]
radius = 31.0
height = 160.0
height = 186.0
[node name="Car" type="CharacterBody2D"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_yiphh"]
size = Vector2(240, 15)
[node name="Car" type="CharacterBody2D" node_paths=PackedStringArray("debugLabel")]
motion_mode = 1
script = ExtResource("1_vkq5y")
debugLabel = NodePath("Label")
[node name="Sprite2D" type="Sprite2D" parent="."]
texture = ExtResource("4_0kman")
@@ -569,7 +574,7 @@ tree_root = SubResource("AnimationNodeBlendTree_q5j17")
advance_expression_base_node = NodePath("..")
anim_player = NodePath("../AnimationPlayer")
parameters/CarStates/driving/blend_position = Vector2(0.0425786, -0.23119)
parameters/CarStates/idling/blend_position = Vector2(-0.000397921, -0.120715)
parameters/CarStates/idling/blend_position = Vector2(-0.31635, 0.279753)
parameters/TimeScale/scale = 1.0
[node name="CollisionHorizontal" type="CollisionShape2D" parent="."]
@@ -581,3 +586,16 @@ shape = SubResource("CapsuleShape2D_l8rwt")
position = Vector2(1, 2)
rotation = -3.14159
shape = SubResource("CapsuleShape2D_l8rwt")
[node name="Label" type="Label" parent="."]
offset_left = 72.0
offset_top = -42.0
offset_right = 112.0
offset_bottom = -19.0
[node name="ZIndexControler" parent="." instance=ExtResource("3_iaqxo")]
[node name="ShapeCast2D" type="ShapeCast2D" parent="ZIndexControler"]
position = Vector2(1, -13)
shape = SubResource("RectangleShape2D_yiphh")
target_position = Vector2(0, -46)

View File

@@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://brh7cqaxc13ie"]
[ext_resource type="Script" path="res://zindex/z_index_controler.gd" id="1_fn0ft"]
[node name="ZIndexControler" type="Node2D"]
script = ExtResource("1_fn0ft")

View File

@@ -0,0 +1,22 @@
extends Node2D
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
var hasManipulatedZIndex = false
if $ShapeCast2D.is_colliding():
var nbCollisions = $ShapeCast2D.get_collision_count()
for n in range(8):
var colider = $ShapeCast2D.get_collider(n) as Node2D
if colider != null:
(get_parent() as Node2D).z_index = colider.z_index+1
hasManipulatedZIndex = true
print((get_parent() as Node2D).z_index)
if !hasManipulatedZIndex:
(get_parent() as Node2D).z_index = 100