From 7e7831eefba93429e081f1d3f3ab788ddad2b890 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 25 Nov 2023 13:24:15 +0100 Subject: [PATCH 1/7] Fix things --- Player.gd | 1 + Root.tscn | 6 +++++- Unshaded.material | Bin 0 -> 731 bytes 3 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 Unshaded.material diff --git a/Player.gd b/Player.gd index 06a4c08..7d1d981 100644 --- a/Player.gd +++ b/Player.gd @@ -1,4 +1,5 @@ extends CharacterBody3D +class_name Player const SPEED = 5.0 diff --git a/Root.tscn b/Root.tscn index 8d50cd6..07de021 100644 --- a/Root.tscn +++ b/Root.tscn @@ -1,15 +1,18 @@ -[gd_scene load_steps=8 format=3 uid="uid://4whij2hmts0t"] +[gd_scene load_steps=9 format=3 uid="uid://4whij2hmts0t"] [ext_resource type="Script" path="res://Player.gd" id="1_wt4gx"] +[ext_resource type="Material" uid="uid://dondfiavgo2ws" path="res://Unshaded.material" id="2_upp15"] [sub_resource type="CapsuleShape3D" id="CapsuleShape3D_castg"] [sub_resource type="CapsuleMesh" id="CapsuleMesh_pnmjt"] +material = ExtResource("2_upp15") [sub_resource type="BoxShape3D" id="BoxShape3D_kpyw3"] size = Vector3(1, 0.1, 3) [sub_resource type="BoxMesh" id="BoxMesh_4tnse"] +material = ExtResource("2_upp15") size = Vector3(1, 0.1, 3) [sub_resource type="PlaneMesh" id="PlaneMesh_opk07"] @@ -19,6 +22,7 @@ size = Vector3(1, 0.1, 3) [node name="Root" type="Node3D"] [node name="Player" type="CharacterBody3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.927202, 0) script = ExtResource("1_wt4gx") [node name="Man" type="CollisionShape3D" parent="Player"] diff --git a/Unshaded.material b/Unshaded.material new file mode 100644 index 0000000000000000000000000000000000000000..d02fcd5637f4175c65af1aee56e0b917edc6f818 GIT binary patch literal 731 zcmV<10wn!XQ$s@n000005C8y51^@uV0ssIgwJ-f(N(Ido0On$4G;m9j4*a>Qs;a80 zD&B9TH6kbf-kY#P5<=wOlGI+o{lYj9y5-*<$k=LI`o8|}>;M0M3RM7909OE;{7>)* zQpw1gLhkM^hQfqEvDJS8{PCwZVo-Ew1 zDaBXHWbqmvuU+V#Y|h93i#N0AUaQok!OKmsMPOV9C2QFnMbWe%)-kd^YGiIOo{a`vj?a5x-}h_t*Qt)*g&Oglz}%apsbDay)tIGhpOdpHss z4I2fk*qJt!LI&N11GTgfvXZ>m@KTzz%0*!x(^V?|;4U(NEMus{Jj0*oJG*d}xhUk@e3V@xh21n+WJ2X4t&Kj5SzAT!%SGCZ z6RmWy{GjbpKB}~GR)YswylhY~u4Gpegls`p3xI&AVW~k%8KN0YQo9&H0z#lFq6ZS- z(}9vi5}6_rVwlRZzX9JVwRNiv%ww(_;iavv)ZL}uXwhD;2N@x6Of>cH>?Ho?;Od1T z!i>yWxDZ9{!9x)gF6~rE`6-{?xfb?%?Xs_422P!Lt`^~SP?ED(323AM`m`J`tmXc616isA#ltg1;D--YsU0lE Date: Sat, 25 Nov 2023 13:49:33 +0100 Subject: [PATCH 2/7] Move --- Player.gd | 54 ++++++++++++++++++++++++++++++++------------------- Root.tscn | 17 +++++++++++----- project.godot | 32 ++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 25 deletions(-) diff --git a/Player.gd b/Player.gd index 7d1d981..9a90895 100644 --- a/Player.gd +++ b/Player.gd @@ -2,31 +2,45 @@ extends CharacterBody3D class_name Player -const SPEED = 5.0 -const JUMP_VELOCITY = 4.5 +@export var input_accel: float = 1.0 +@onready var current_input_accel = input_accel + +@onready var gravity_accel: Vector3 = ProjectSettings.get_setting("physics/3d/default_gravity") * ProjectSettings.get_setting("physics/3d/default_gravity_vector") +@export var jump_impulse: Vector3 = Vector3.UP * 100.0; + + +@export var max_jumps = 1 +@onready var current_jumps = max_jumps + + +func refill_jumps(): + current_jumps = max_jumps + + +func do_jump(): + current_jumps -= 1 + velocity += jump_impulse -# Get the gravity from the project settings to be synced with RigidBody nodes. -var gravity = ProjectSettings.get_setting("physics/3d/default_gravity") func _physics_process(delta): - # Add the gravity. - if not is_on_floor(): - velocity.y -= gravity * delta + # Refilla salto + if is_on_floor(): + refill_jumps() + + # Rileva salto + if Input.is_action_just_pressed("jump") and current_jumps > 0: + do_jump() + + # Applica gravità + velocity += gravity_accel - # Handle Jump. - if Input.is_action_just_pressed("ui_accept") and is_on_floor(): - velocity.y = JUMP_VELOCITY + # Applica input + var input_dir = Input.get_vector("move_left", "move_right", "move_up", "move_down") + var input_change = input_dir * input_accel + velocity.x += input_change.x + velocity.z += input_change.y - # Get the input direction and handle the movement/deceleration. - # As good practice, you should replace UI actions with custom gameplay actions. - var input_dir = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down") - var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized() - if direction: - velocity.x = direction.x * SPEED - velocity.z = direction.z * SPEED - else: - velocity.x = move_toward(velocity.x, 0, SPEED) - velocity.z = move_toward(velocity.z, 0, SPEED) + print(velocity) move_and_slide() diff --git a/Root.tscn b/Root.tscn index 07de021..32f72dc 100644 --- a/Root.tscn +++ b/Root.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=9 format=3 uid="uid://4whij2hmts0t"] +[gd_scene load_steps=10 format=3 uid="uid://4whij2hmts0t"] [ext_resource type="Script" path="res://Player.gd" id="1_wt4gx"] [ext_resource type="Material" uid="uid://dondfiavgo2ws" path="res://Unshaded.material" id="2_upp15"] @@ -15,9 +15,16 @@ size = Vector3(1, 0.1, 3) material = ExtResource("2_upp15") size = Vector3(1, 0.1, 3) -[sub_resource type="PlaneMesh" id="PlaneMesh_opk07"] +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_1au4d"] +shading_mode = 0 +albedo_color = Color(0, 0.541176, 0, 1) -[sub_resource type="WorldBoundaryShape3D" id="WorldBoundaryShape3D_tpbxa"] +[sub_resource type="PlaneMesh" id="PlaneMesh_opk07"] +material = SubResource("StandardMaterial3D_1au4d") +size = Vector2(200, 200) + +[sub_resource type="BoxShape3D" id="BoxShape3D_2bm1d"] +size = Vector3(200, 4, 200) [node name="Root" type="Node3D"] @@ -44,11 +51,11 @@ skeleton = NodePath("../..") [node name="Plane" type="StaticBody3D" parent="."] [node name="MeshInstance3D" type="MeshInstance3D" parent="Plane"] -transform = Transform3D(100, 0, 0, 0, 1, 0, 0, 0, 100, 0, 0, 0) mesh = SubResource("PlaneMesh_opk07") [node name="CollisionShape3D" type="CollisionShape3D" parent="Plane"] -shape = SubResource("WorldBoundaryShape3D_tpbxa") +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -2, 0) +shape = SubResource("BoxShape3D_2bm1d") [node name="Camera3D" type="Camera3D" parent="."] transform = Transform3D(1, 0, 0, 0, 0.955149, 0.296125, 0, -0.296125, 0.955149, 0, 2.66196, 3.33182) diff --git a/project.godot b/project.godot index da8c83a..89ac43a 100644 --- a/project.godot +++ b/project.godot @@ -14,3 +14,35 @@ config/name="cisio" run/main_scene="res://Root.tscn" config/features=PackedStringArray("4.1", "Forward Plus") config/icon="res://icon.svg" + +[input] + +jump={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"echo":false,"script":null) +] +} +move_up={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194320,"key_label":0,"unicode":0,"echo":false,"script":null) +] +} +move_down={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194322,"key_label":0,"unicode":0,"echo":false,"script":null) +] +} +move_left={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194319,"key_label":0,"unicode":0,"echo":false,"script":null) +] +} +move_right={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"echo":false,"script":null) +] +} From d465676cc4fc9f65e26c8a30e147449e1a73e7be Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 25 Nov 2023 13:51:24 +0100 Subject: [PATCH 3/7] Delta --- Player.gd | 6 +++--- Root.tscn | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Player.gd b/Player.gd index 9a90895..b21c839 100644 --- a/Player.gd +++ b/Player.gd @@ -33,13 +33,13 @@ func _physics_process(delta): do_jump() # Applica gravità - velocity += gravity_accel + velocity += gravity_accel * delta # Applica input var input_dir = Input.get_vector("move_left", "move_right", "move_up", "move_down") var input_change = input_dir * input_accel - velocity.x += input_change.x - velocity.z += input_change.y + velocity.x += input_change.x * delta + velocity.z += input_change.y * delta print(velocity) diff --git a/Root.tscn b/Root.tscn index 32f72dc..e176a83 100644 --- a/Root.tscn +++ b/Root.tscn @@ -59,3 +59,5 @@ shape = SubResource("BoxShape3D_2bm1d") [node name="Camera3D" type="Camera3D" parent="."] transform = Transform3D(1, 0, 0, 0, 0.955149, 0.296125, 0, -0.296125, 0.955149, 0, 2.66196, 3.33182) + +[node name="Timer" type="Node" parent="."] From 7829f6465ed290c187578d6225161f30107537e2 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 25 Nov 2023 13:52:47 +0100 Subject: [PATCH 4/7] decrease impulse --- Player.gd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Player.gd b/Player.gd index b21c839..7539a62 100644 --- a/Player.gd +++ b/Player.gd @@ -6,7 +6,7 @@ class_name Player @onready var current_input_accel = input_accel @onready var gravity_accel: Vector3 = ProjectSettings.get_setting("physics/3d/default_gravity") * ProjectSettings.get_setting("physics/3d/default_gravity_vector") -@export var jump_impulse: Vector3 = Vector3.UP * 100.0; +@export var jump_impulse: Vector3 = Vector3.UP; @export var max_jumps = 1 From 9a2db45d0ecb2d61273fe457e8af122bfe34ab8f Mon Sep 17 00:00:00 2001 From: Leonardo <321501@studenti.unimore.it> Date: Sat, 25 Nov 2023 13:55:40 +0100 Subject: [PATCH 5/7] hcancged jump --- Player.gd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Player.gd b/Player.gd index 7539a62..b86dfc2 100644 --- a/Player.gd +++ b/Player.gd @@ -6,7 +6,7 @@ class_name Player @onready var current_input_accel = input_accel @onready var gravity_accel: Vector3 = ProjectSettings.get_setting("physics/3d/default_gravity") * ProjectSettings.get_setting("physics/3d/default_gravity_vector") -@export var jump_impulse: Vector3 = Vector3.UP; +@export var jump_impulse: Vector3 = Vector3.UP * 5; @export var max_jumps = 1 From c2373eaf9b0560339e2628cf5055feba325d4852 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 25 Nov 2023 14:00:43 +0100 Subject: [PATCH 6/7] Add tmer --- GameTimer.gd | 12 ++++++++++++ Root.tscn | 26 ++++++++++++++++++++++++-- Unshaded.material | Bin 731 -> 728 bytes 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 GameTimer.gd diff --git a/GameTimer.gd b/GameTimer.gd new file mode 100644 index 0000000..fec09bf --- /dev/null +++ b/GameTimer.gd @@ -0,0 +1,12 @@ +extends Node +class_name GameTimer + + +var current_time := 0.0 + +@onready var parent: Label = get_parent() + + +func _process(delta): + current_time += delta + parent.text = "%0.2f" % current_time diff --git a/Root.tscn b/Root.tscn index e176a83..2aacd22 100644 --- a/Root.tscn +++ b/Root.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=10 format=3 uid="uid://4whij2hmts0t"] +[gd_scene load_steps=11 format=3 uid="uid://4whij2hmts0t"] [ext_resource type="Script" path="res://Player.gd" id="1_wt4gx"] [ext_resource type="Material" uid="uid://dondfiavgo2ws" path="res://Unshaded.material" id="2_upp15"] +[ext_resource type="Script" path="res://GameTimer.gd" id="3_y362g"] [sub_resource type="CapsuleShape3D" id="CapsuleShape3D_castg"] @@ -60,4 +61,25 @@ shape = SubResource("BoxShape3D_2bm1d") [node name="Camera3D" type="Camera3D" parent="."] transform = Transform3D(1, 0, 0, 0, 0.955149, 0.296125, 0, -0.296125, 0.955149, 0, 2.66196, 3.33182) -[node name="Timer" type="Node" parent="."] +[node name="Control" type="Control" parent="."] +layout_mode = 3 +anchors_preset = 1 +anchor_left = 1.0 +anchor_right = 1.0 +offset_left = -40.0 +offset_bottom = 40.0 +grow_horizontal = 0 + +[node name="Label" type="Label" parent="Control"] +layout_mode = 1 +anchors_preset = 1 +anchor_left = 1.0 +anchor_right = 1.0 +offset_left = -81.0 +offset_bottom = 26.0 +grow_horizontal = 0 +text = "Garasauto" +horizontal_alignment = 2 + +[node name="GameTimer" type="Node" parent="Control/Label"] +script = ExtResource("3_y362g") diff --git a/Unshaded.material b/Unshaded.material index d02fcd5637f4175c65af1aee56e0b917edc6f818..38968259f33643897450b8e7c417424e6abd727a 100644 GIT binary patch literal 728 zcmV;}0w?`aQ$s@n000005C8x{1^@uS0ssIgwJ-f(K?SuH0M=qMz%)eCbAIf3BdVfllU0ulze$08)z#B!9z!gBL!3dRRC82s{Bvz z$+F0&)*ko&1z+ow^@ICg;*(BJ$;uefQXHGxiR0q3EVbz^Nevfv(n9`!@gKuMco3mR z9MI_SU%)j~&`ZX?4Tulz^~V1P{|WpD@PEJ`i>9tY$bScC&}ytAF(%>2PCwWTt~_|z zN{c6iik_`APMQ{buo)x&G2W0zs`X+j%^9k43j&`y3#x_7VVFdZO>~ge3)|94j*&rH zAyRb~M5!^f7?OlAlDHrrDr9U;#^G={91=)5N!G$ue2`^)d#aMVaWPDy5OEkMrxtN2 zKCEjLXkH^y+&#!*7!5XMFUJhBUc+fq>BYxhn@VLO{5jR*Q>G9R>MaWe88kLDE+F_H zpuohN2?&=%Muvrj+$wo7@SJU8;HI{d@Uh3H_@pvi_If3{Ky-{vI-7hFtEG9|hPq_) zRrF?37$TP;e3I#PQgbFr{P5;s@yzOMzPXP_7pxv(?i$V-tn&dVCl0z?Px42nO=~MIgqOy{s98 zYmUc1FdGxRg-?2NsKnY=33yYF#ohmtJ3n49AtjNSB_V`bRK~r=4j*V$o5A5mtCU_c z0L%*0Sk6LQJ|QHoRIQ@IRquXAI*ppL8PeO?3Qz*m;sSgh0W}Bu3NAwIF(H3wkMjiN zhjs@j#C6TshT=4|nGXXT#8Qyn1m2KRx_w`Cd*=9SW=-U39596u``*ZFsUrE{e%yZN KKLK@8Q$s^Fcu1W9 literal 731 zcmV<10wn!XQ$s@n000005C8y51^@uV0ssIgwJ-f(N(Ido0On$4G;m9j4*a>Qs;a80 zD&B9TH6kbf-kY#P5<=wOlGI+o{lYj9y5-*<$k=LI`o8|}>;M0M3RM7909OE;{7>)* zQpw1gLhkM^hQfqEvDJS8{PCwZVo-Ew1 zDaBXHWbqmvuU+V#Y|h93i#N0AUaQok!OKmsMPOV9C2QFnMbWe%)-kd^YGiIOo{a`vj?a5x-}h_t*Qt)*g&Oglz}%apsbDay)tIGhpOdpHss z4I2fk*qJt!LI&N11GTgfvXZ>m@KTzz%0*!x(^V?|;4U(NEMus{Jj0*oJG*d}xhUk@e3V@xh21n+WJ2X4t&Kj5SzAT!%SGCZ z6RmWy{GjbpKB}~GR)YswylhY~u4Gpegls`p3xI&AVW~k%8KN0YQo9&H0z#lFq6ZS- z(}9vi5}6_rVwlRZzX9JVwRNiv%ww(_;iavv)ZL}uXwhD;2N@x6Of>cH>?Ho?;Od1T z!i>yWxDZ9{!9x)gF6~rE`6-{?xfb?%?Xs_422P!Lt`^~SP?ED(323AM`m`J`tmXc616isA#ltg1;D--YsU0lE Date: Sat, 25 Nov 2023 14:14:59 +0100 Subject: [PATCH 7/7] Check for collision normal on horizontal collisions --- Player.gd | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Player.gd b/Player.gd index b86dfc2..254556c 100644 --- a/Player.gd +++ b/Player.gd @@ -12,6 +12,8 @@ class_name Player @export var max_jumps = 1 @onready var current_jumps = max_jumps +@export var collision_normal_max_y_for_floor: float = 0.9 + func refill_jumps(): current_jumps = max_jumps @@ -41,6 +43,12 @@ func _physics_process(delta): velocity.x += input_change.x * delta velocity.z += input_change.y * delta - print(velocity) - move_and_slide() + + # Gestisci collisioni + for collision_idx in range(get_slide_collision_count()): + var collision = get_slide_collision(collision_idx) + if collision.get_normal().y > collision_normal_max_y_for_floor: + continue + print("bonk") +