From af1bdeb3ca7d83d76f277239a1a3ec5a790fe18c Mon Sep 17 00:00:00 2001 From: AmyLillya Date: Mon, 4 Sep 2023 17:50:43 -0300 Subject: [PATCH] added debug stuff --- Autoload/Debug.gd | 11 +++++++++++ Autoload/Debug.tscn | 6 ++++++ Ball/ball.gd | 11 ++++++++++- Ball/ball.tscn | 2 +- project.godot | 9 +++++++++ 5 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 Autoload/Debug.gd create mode 100644 Autoload/Debug.tscn diff --git a/Autoload/Debug.gd b/Autoload/Debug.gd new file mode 100644 index 0000000..dcdbb67 --- /dev/null +++ b/Autoload/Debug.gd @@ -0,0 +1,11 @@ +extends Node + + +func _process(delta): + if Input.is_action_just_pressed("debug_1"): + print("total balls: ", get_total_ball_count()) + + +func get_total_ball_count(): + var total_balls : int = get_tree().get_nodes_in_group("Balls").size() + return total_balls diff --git a/Autoload/Debug.tscn b/Autoload/Debug.tscn new file mode 100644 index 0000000..2798344 --- /dev/null +++ b/Autoload/Debug.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3 uid="uid://cpey4r5s1qsy8"] + +[ext_resource type="Script" path="res://Autoload/Debug.gd" id="1_imoie"] + +[node name="Debug" type="Node"] +script = ExtResource("1_imoie") diff --git a/Ball/ball.gd b/Ball/ball.gd index ae34fe3..3d1e75c 100644 --- a/Ball/ball.gd +++ b/Ball/ball.gd @@ -9,6 +9,7 @@ var bounced_velocity : Vector3 var just_collided = false var total_bounce_duration = 0.5 +var bounce_factor_cap = 0.25 func _physics_process(delta): @@ -17,6 +18,14 @@ func _physics_process(delta): captured_velocity = linear_velocity _get_collision(delta) + + + + ### DEBUG + # Delete balls that escape the level + if global_position.length() > 20.0: + print("ball deleted, total: ", Debug.get_total_ball_count()) + queue_free() var collision_normal : Vector3 @@ -35,7 +44,7 @@ func _get_collision(delta): collision_angle_factor = collision_normal.dot(captured_velocity.normalized() * -1) # Cap the factor for collision angles that are too shallow - if collision_angle_factor < 0.25: + if collision_angle_factor < bounce_factor_cap: collision_angle_factor = 0 # Bounce back immediately if factor is 0 diff --git a/Ball/ball.tscn b/Ball/ball.tscn index 24fd9fe..e5bf631 100644 --- a/Ball/ball.tscn +++ b/Ball/ball.tscn @@ -8,7 +8,7 @@ [sub_resource type="SphereShape3D" id="SphereShape3D_ogc07"] radius = 0.3 -[node name="Ball" type="RigidBody3D"] +[node name="Ball" type="RigidBody3D" groups=["Balls"]] collision_layer = 4 custom_integrator = true max_contacts_reported = 1 diff --git a/project.godot b/project.godot index 1491771..bba1a80 100644 --- a/project.godot +++ b/project.godot @@ -15,6 +15,10 @@ run/main_scene="res://World/world.tscn" config/features=PackedStringArray("4.1", "Forward Plus") config/icon="res://icon.svg" +[autoload] + +Debug="*res://Autoload/Debug.tscn" + [input] move_left={ @@ -48,6 +52,11 @@ shoot={ , 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":69,"key_label":0,"unicode":101,"echo":false,"script":null) ] } +debug_1={ +"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":49,"key_label":0,"unicode":49,"echo":false,"script":null) +] +} [layer_names]