Compare commits
7 Commits
advanced_b
...
main
Author | SHA1 | Date |
---|---|---|
|
38be890bd8 | |
|
5e9eb8b74e | |
|
15274ea71a | |
|
b727d46c5e | |
|
a904d18eb1 | |
|
af1bdeb3ca | |
|
22f17fdbff |
|
@ -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
|
|
@ -0,0 +1,11 @@
|
|||
extends Node
|
||||
|
||||
|
||||
# Apply this small offset to the up vector in the look_at function to fix it
|
||||
# not working when the target is perfectly aligned with the up vector
|
||||
const LOOK_AT_OFFSET_FIX = Vector3(0.01, 1, 0.01)
|
||||
|
||||
|
||||
# Compose an uniform Vector3 from a float value
|
||||
func uniform_vec3(value : float):
|
||||
return Vector3(value, value, value)
|
|
@ -7,5 +7,5 @@
|
|||
render_priority = 0
|
||||
shader = ExtResource("1_kfvtm")
|
||||
shader_parameter/intensity = 1.0
|
||||
shader_parameter/color = Color(0.333333, 0.545098, 0.976471, 1)
|
||||
shader_parameter/color = Color(0.333333, 0.545098, 0.976471, 0.862745)
|
||||
shader_parameter/matcap = ExtResource("2_o5lk5")
|
||||
|
|
|
@ -14,4 +14,5 @@ void fragment() {
|
|||
vec2 matcap_uv = (NORMAL.xy * vec2(0.5, -0.5) + vec2(0.5, 0.5));
|
||||
ALBEDO = color.rgb;
|
||||
ALBEDO *= mix(vec3(1.0), texture(matcap, matcap_uv).rgb, intensity);
|
||||
ALPHA = color.a;
|
||||
}
|
Binary file not shown.
|
@ -1,39 +0,0 @@
|
|||
[remap]
|
||||
|
||||
importer="scene"
|
||||
importer_version=1
|
||||
type="PackedScene"
|
||||
uid="uid://ctsvwwopru2jf"
|
||||
path="res://.godot/imported/ball_tail.glb-e1c9b3c5d2a8f19476283eb997d8e59c.scn"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://Ball/Meshes/ball_tail.glb"
|
||||
dest_files=["res://.godot/imported/ball_tail.glb-e1c9b3c5d2a8f19476283eb997d8e59c.scn"]
|
||||
|
||||
[params]
|
||||
|
||||
nodes/root_type="Node3D"
|
||||
nodes/root_name="Scene Root"
|
||||
nodes/apply_root_scale=true
|
||||
nodes/root_scale=1.0
|
||||
meshes/ensure_tangents=true
|
||||
meshes/generate_lods=true
|
||||
meshes/create_shadow_meshes=true
|
||||
meshes/light_baking=1
|
||||
meshes/lightmap_texel_size=0.2
|
||||
skins/use_named_skins=true
|
||||
animation/import=false
|
||||
animation/fps=30
|
||||
animation/trimming=false
|
||||
animation/remove_immutable_tracks=true
|
||||
import_script/path=""
|
||||
_subresources={
|
||||
"materials": {
|
||||
"Ball": {
|
||||
"use_external/enabled": true,
|
||||
"use_external/path": "res://Ball/Meshes/ball_material.tres"
|
||||
}
|
||||
}
|
||||
}
|
||||
gltf/embedded_image_handling=1
|
|
@ -1,63 +0,0 @@
|
|||
[gd_resource type="VisualShader" load_steps=9 format=3 uid="uid://ny01m62ohegv"]
|
||||
|
||||
[sub_resource type="VisualShaderNodeVectorOp" id="VisualShaderNodeVectorOp_sbl4o"]
|
||||
operator = 8
|
||||
|
||||
[sub_resource type="VisualShaderNodeVectorCompose" id="VisualShaderNodeVectorCompose_7ys52"]
|
||||
default_input_values = [0, 0.0, 1, 0.0, 2, 1.0]
|
||||
|
||||
[sub_resource type="VisualShaderNodeVectorDecompose" id="VisualShaderNodeVectorDecompose_o0c6e"]
|
||||
default_input_values = [0, Vector2(0, 0)]
|
||||
op_type = 0
|
||||
|
||||
[sub_resource type="VisualShaderNodeInput" id="VisualShaderNodeInput_5rytf"]
|
||||
input_name = "screen_uv"
|
||||
|
||||
[sub_resource type="VisualShaderNodeVectorOp" id="VisualShaderNodeVectorOp_nwrdd"]
|
||||
default_input_values = [0, Vector2(0, 0), 1, Vector2(0.5, 0.5)]
|
||||
op_type = 0
|
||||
operator = 1
|
||||
|
||||
[sub_resource type="VisualShaderNodeVectorFunc" id="VisualShaderNodeVectorFunc_711ug"]
|
||||
|
||||
[sub_resource type="VisualShaderNodeInput" id="VisualShaderNodeInput_fou4c"]
|
||||
input_name = "normal"
|
||||
|
||||
[sub_resource type="VisualShaderNodeVectorOp" id="VisualShaderNodeVectorOp_2wva2"]
|
||||
operator = 2
|
||||
|
||||
[resource]
|
||||
code = "shader_type spatial;
|
||||
render_mode blend_mix, depth_draw_opaque, cull_back, diffuse_lambert, specular_schlick_ggx;
|
||||
|
||||
|
||||
|
||||
|
||||
void fragment() {
|
||||
// Input:7
|
||||
vec3 n_out7p0 = NORMAL;
|
||||
|
||||
|
||||
// Output:0
|
||||
ALBEDO = n_out7p0;
|
||||
|
||||
|
||||
}
|
||||
"
|
||||
nodes/fragment/3/node = SubResource("VisualShaderNodeInput_5rytf")
|
||||
nodes/fragment/3/position = Vector2(-1780, 340)
|
||||
nodes/fragment/5/node = SubResource("VisualShaderNodeVectorOp_nwrdd")
|
||||
nodes/fragment/5/position = Vector2(-1480, 400)
|
||||
nodes/fragment/6/node = SubResource("VisualShaderNodeVectorFunc_711ug")
|
||||
nodes/fragment/6/position = Vector2(-920, 400)
|
||||
nodes/fragment/7/node = SubResource("VisualShaderNodeInput_fou4c")
|
||||
nodes/fragment/7/position = Vector2(-880, 200)
|
||||
nodes/fragment/9/node = SubResource("VisualShaderNodeVectorOp_2wva2")
|
||||
nodes/fragment/9/position = Vector2(-400, 200)
|
||||
nodes/fragment/10/node = SubResource("VisualShaderNodeVectorOp_sbl4o")
|
||||
nodes/fragment/10/position = Vector2(-200, 260)
|
||||
nodes/fragment/11/node = SubResource("VisualShaderNodeVectorCompose_7ys52")
|
||||
nodes/fragment/11/position = Vector2(-1120, 400)
|
||||
nodes/fragment/12/node = SubResource("VisualShaderNodeVectorDecompose_o0c6e")
|
||||
nodes/fragment/12/position = Vector2(-1320, 400)
|
||||
nodes/fragment/connections = PackedInt32Array(3, 0, 5, 0, 7, 0, 9, 0, 9, 0, 10, 0, 6, 0, 10, 1, 5, 0, 11, 0, 5, 0, 12, 0, 12, 1, 11, 1, 11, 0, 6, 0, 3, 0, 9, 1, 7, 0, 0, 0)
|
|
@ -1,71 +0,0 @@
|
|||
[gd_scene load_steps=11 format=3 uid="uid://dd1e3u5cyy3mk"]
|
||||
|
||||
[ext_resource type="Material" uid="uid://ccktnp41cys0r" path="res://Ball/Meshes/ball_material.tres" id="1_5n3i6"]
|
||||
[ext_resource type="Script" path="res://Ball/ball_test.gd" id="1_s3xmr"]
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_jblqj"]
|
||||
radius = 0.1
|
||||
|
||||
[sub_resource type="SphereMesh" id="SphereMesh_52mtx"]
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_862wy"]
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_dwt7q"]
|
||||
|
||||
[sub_resource type="BoxMesh" id="BoxMesh_1auv0"]
|
||||
|
||||
[sub_resource type="SphereMesh" id="SphereMesh_xquva"]
|
||||
radius = 0.2
|
||||
height = 0.4
|
||||
|
||||
[sub_resource type="SphereMesh" id="SphereMesh_bnhf3"]
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_5h0ki"]
|
||||
transparency = 1
|
||||
albedo_color = Color(1, 0.372549, 1, 0.701961)
|
||||
|
||||
[node name="BallBase" type="RigidBody3D"]
|
||||
collision_layer = 0
|
||||
collision_mask = 0
|
||||
gravity_scale = 0.0
|
||||
continuous_cd = true
|
||||
lock_rotation = true
|
||||
linear_damp_mode = 1
|
||||
angular_damp_mode = 1
|
||||
script = ExtResource("1_s3xmr")
|
||||
speed = 20.0
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
shape = SubResource("SphereShape3D_jblqj")
|
||||
|
||||
[node name="BallMesh" type="MeshInstance3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.0029127)
|
||||
mesh = SubResource("SphereMesh_52mtx")
|
||||
surface_material_override/0 = ExtResource("1_5n3i6")
|
||||
|
||||
[node name="BallBody" type="StaticBody3D" parent="."]
|
||||
collision_layer = 4
|
||||
collision_mask = 5
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="BallBody"]
|
||||
shape = SubResource("SphereShape3D_862wy")
|
||||
|
||||
[node name="AnchorBody3D" type="StaticBody3D" parent="."]
|
||||
top_level = true
|
||||
collision_layer = 4
|
||||
collision_mask = 5
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="AnchorBody3D"]
|
||||
shape = SubResource("SphereShape3D_dwt7q")
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="AnchorBody3D"]
|
||||
mesh = SubResource("BoxMesh_1auv0")
|
||||
|
||||
[node name="TestMesh" type="MeshInstance3D" parent="."]
|
||||
visible = false
|
||||
mesh = SubResource("SphereMesh_xquva")
|
||||
|
||||
[node name="TestMesh2" type="MeshInstance3D" parent="."]
|
||||
visible = false
|
||||
mesh = SubResource("SphereMesh_bnhf3")
|
||||
surface_material_override/0 = SubResource("StandardMaterial3D_5h0ki")
|
|
@ -1,35 +0,0 @@
|
|||
[gd_scene load_steps=5 format=3 uid="uid://rdlvlyf0l1l"]
|
||||
|
||||
[ext_resource type="Script" path="res://Ball/ball.gd" id="1_oenn5"]
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_b4pqe"]
|
||||
size = Vector3(0.5, 0.5, 0.5)
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_tdblm"]
|
||||
albedo_color = Color(0.117647, 0.427451, 0.611765, 1)
|
||||
roughness = 0.42
|
||||
|
||||
[sub_resource type="SphereMesh" id="SphereMesh_mq1q1"]
|
||||
radius = 0.3
|
||||
height = 0.6
|
||||
|
||||
[node name="Ball" type="RigidBody3D"]
|
||||
collision_layer = 4
|
||||
custom_integrator = true
|
||||
max_contacts_reported = 1
|
||||
contact_monitor = true
|
||||
can_sleep = false
|
||||
lock_rotation = true
|
||||
linear_damp_mode = 1
|
||||
angular_damp_mode = 1
|
||||
script = ExtResource("1_oenn5")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
shape = SubResource("BoxShape3D_b4pqe")
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||
material_override = SubResource("StandardMaterial3D_tdblm")
|
||||
mesh = SubResource("SphereMesh_mq1q1")
|
||||
|
||||
[node name="TimerCollision" type="Timer" parent="."]
|
||||
one_shot = true
|
|
@ -1,36 +0,0 @@
|
|||
[gd_scene load_steps=6 format=3 uid="uid://rdlvlyf0l1l"]
|
||||
|
||||
[ext_resource type="Script" path="res://Ball/ball.gd" id="1_oenn5"]
|
||||
[ext_resource type="PackedScene" uid="uid://lge7m41oi6pn" path="res://Ball/Meshes/ball_bouncing.glb" id="2_ccq7m"]
|
||||
[ext_resource type="PackedScene" uid="uid://b1embyb2knvho" path="res://Ball/Meshes/ball_flying.glb" id="4_fh5j8"]
|
||||
[ext_resource type="Script" path="res://Ball/ball_meshes.gd" id="4_llldm"]
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_ogc07"]
|
||||
radius = 0.3
|
||||
|
||||
[node name="Ball" type="RigidBody3D"]
|
||||
collision_layer = 4
|
||||
custom_integrator = true
|
||||
max_contacts_reported = 1
|
||||
contact_monitor = true
|
||||
can_sleep = false
|
||||
lock_rotation = true
|
||||
linear_damp_mode = 1
|
||||
angular_damp_mode = 1
|
||||
script = ExtResource("1_oenn5")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
shape = SubResource("SphereShape3D_ogc07")
|
||||
|
||||
[node name="TimerCollision" type="Timer" parent="."]
|
||||
one_shot = true
|
||||
|
||||
[node name="Meshes" type="Node3D" parent="."]
|
||||
script = ExtResource("4_llldm")
|
||||
|
||||
[node name="BallBouncingMesh" parent="Meshes" instance=ExtResource("2_ccq7m")]
|
||||
visible = false
|
||||
|
||||
[node name="BallFlyingMesh" parent="Meshes" instance=ExtResource("4_fh5j8")]
|
||||
|
||||
[node name="RotationNode" type="Node3D" parent="Meshes"]
|
|
@ -1,40 +0,0 @@
|
|||
[gd_scene load_steps=7 format=3 uid="uid://rdlvlyf0l1l"]
|
||||
|
||||
[ext_resource type="Script" path="res://Ball/ball.gd" id="1_oenn5"]
|
||||
[ext_resource type="Shader" uid="uid://ny01m62ohegv" path="res://Ball/Meshes/ball_visual_shader.tres" id="2_wbu40"]
|
||||
[ext_resource type="PackedScene" uid="uid://dn8tw0i6t3701" path="res://Ball/ball_mesh_bouncing.tscn" id="3_3pvgr"]
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_ogc07"]
|
||||
radius = 0.3
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_qwhgq"]
|
||||
render_priority = 0
|
||||
shader = ExtResource("2_wbu40")
|
||||
|
||||
[sub_resource type="SphereMesh" id="SphereMesh_mq1q1"]
|
||||
radius = 0.3
|
||||
height = 0.6
|
||||
|
||||
[node name="Ball" type="RigidBody3D"]
|
||||
collision_layer = 4
|
||||
custom_integrator = true
|
||||
max_contacts_reported = 1
|
||||
contact_monitor = true
|
||||
can_sleep = false
|
||||
lock_rotation = true
|
||||
linear_damp_mode = 1
|
||||
angular_damp_mode = 1
|
||||
script = ExtResource("1_oenn5")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
shape = SubResource("SphereShape3D_ogc07")
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||
visible = false
|
||||
material_override = SubResource("ShaderMaterial_qwhgq")
|
||||
mesh = SubResource("SphereMesh_mq1q1")
|
||||
|
||||
[node name="TimerCollision" type="Timer" parent="."]
|
||||
one_shot = true
|
||||
|
||||
[node name="BallBouncingMesh" parent="." instance=ExtResource("3_3pvgr")]
|
|
@ -1,71 +0,0 @@
|
|||
[gd_scene load_steps=11 format=3 uid="uid://dd1e3u5cyy3mk"]
|
||||
|
||||
[ext_resource type="Material" uid="uid://ccktnp41cys0r" path="res://Ball/Meshes/ball_material.tres" id="1_5n3i6"]
|
||||
[ext_resource type="Script" path="res://Ball/ball_test.gd" id="1_s3xmr"]
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_jblqj"]
|
||||
radius = 0.1
|
||||
|
||||
[sub_resource type="SphereMesh" id="SphereMesh_52mtx"]
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_862wy"]
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_dwt7q"]
|
||||
|
||||
[sub_resource type="BoxMesh" id="BoxMesh_1auv0"]
|
||||
|
||||
[sub_resource type="SphereMesh" id="SphereMesh_xquva"]
|
||||
radius = 0.2
|
||||
height = 0.4
|
||||
|
||||
[sub_resource type="SphereMesh" id="SphereMesh_bnhf3"]
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_5h0ki"]
|
||||
transparency = 1
|
||||
albedo_color = Color(1, 0.372549, 1, 0.701961)
|
||||
|
||||
[node name="BallBase" type="RigidBody3D"]
|
||||
collision_layer = 0
|
||||
collision_mask = 0
|
||||
gravity_scale = 0.0
|
||||
continuous_cd = true
|
||||
lock_rotation = true
|
||||
linear_damp_mode = 1
|
||||
angular_damp_mode = 1
|
||||
script = ExtResource("1_s3xmr")
|
||||
speed = 20.0
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
shape = SubResource("SphereShape3D_jblqj")
|
||||
|
||||
[node name="BallMesh" type="MeshInstance3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.0029127)
|
||||
mesh = SubResource("SphereMesh_52mtx")
|
||||
surface_material_override/0 = ExtResource("1_5n3i6")
|
||||
|
||||
[node name="BallBody" type="StaticBody3D" parent="."]
|
||||
collision_layer = 4
|
||||
collision_mask = 5
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="BallBody"]
|
||||
shape = SubResource("SphereShape3D_862wy")
|
||||
|
||||
[node name="AnchorBody3D" type="StaticBody3D" parent="."]
|
||||
top_level = true
|
||||
collision_layer = 4
|
||||
collision_mask = 5
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="AnchorBody3D"]
|
||||
shape = SubResource("SphereShape3D_dwt7q")
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="AnchorBody3D"]
|
||||
mesh = SubResource("BoxMesh_1auv0")
|
||||
|
||||
[node name="TestMesh" type="MeshInstance3D" parent="."]
|
||||
visible = false
|
||||
mesh = SubResource("SphereMesh_xquva")
|
||||
|
||||
[node name="TestMesh2" type="MeshInstance3D" parent="."]
|
||||
visible = false
|
||||
mesh = SubResource("SphereMesh_bnhf3")
|
||||
surface_material_override/0 = SubResource("StandardMaterial3D_5h0ki")
|
55
Ball/ball.gd
55
Ball/ball.gd
|
@ -9,7 +9,7 @@ var bounced_velocity : Vector3
|
|||
var just_collided = false
|
||||
|
||||
var total_bounce_duration = 0.5
|
||||
var gravity = Vector3(0, -10, 0)
|
||||
var bounce_factor_cap = 0.25
|
||||
|
||||
|
||||
func _physics_process(delta):
|
||||
|
@ -18,8 +18,16 @@ 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_position : Vector3
|
||||
var collision_normal : Vector3
|
||||
var collision_angle_factor : float
|
||||
func _get_collision(delta):
|
||||
|
@ -30,27 +38,37 @@ func _get_collision(delta):
|
|||
# A collision happens
|
||||
if collision:
|
||||
# Get collision data stuff
|
||||
collision_position = collision.get_position()
|
||||
collision_normal = collision.get_normal()
|
||||
bounced_velocity = captured_velocity.bounce(collision_normal)
|
||||
# Get the dot product between the surface normal and the ball direction on hit
|
||||
collision_angle_factor = collision_normal.dot(captured_velocity.normalized() * -1)
|
||||
|
||||
# Set the duration of the timer based on the collision angle
|
||||
$TimerCollision.wait_time = total_bounce_duration * collision_angle_factor
|
||||
$TimerCollision.start()
|
||||
# Cap the factor for collision angles that are too shallow
|
||||
if collision_angle_factor < bounce_factor_cap:
|
||||
collision_angle_factor = 0
|
||||
|
||||
# Send the signal after getting the data to avoid having zeroed values
|
||||
just_collided = true
|
||||
emit_signal("ball_collision_started")
|
||||
|
||||
# Completely stop the ball in place
|
||||
linear_velocity = Vector3.ZERO
|
||||
freeze = true
|
||||
|
||||
# Move the ball again after the timer runs out
|
||||
# The if check prevents the timeout function from trying to connect every frame
|
||||
if not $TimerCollision.timeout.is_connected(_after_collision):
|
||||
$TimerCollision.timeout.connect(_after_collision)
|
||||
# Bounce back immediately if factor is 0
|
||||
if collision_angle_factor == 0:
|
||||
_after_collision()
|
||||
# Do the sticky behaviour otherwise
|
||||
else:
|
||||
# Set the duration of the timer based on the collision angle
|
||||
$TimerCollision.wait_time = total_bounce_duration * collision_angle_factor
|
||||
$TimerCollision.start()
|
||||
|
||||
# Send the signal after getting the data to avoid having zeroed values
|
||||
just_collided = true
|
||||
emit_signal("ball_collision_started")
|
||||
|
||||
# Completely stop the ball in place
|
||||
linear_velocity = Vector3.ZERO
|
||||
freeze = true
|
||||
|
||||
# Move the ball again after the timer runs out
|
||||
# The if check prevents the timeout function from trying to connect every frame
|
||||
if not $TimerCollision.timeout.is_connected(_after_collision):
|
||||
$TimerCollision.timeout.connect(_after_collision)
|
||||
|
||||
|
||||
func _after_collision():
|
||||
|
@ -60,3 +78,8 @@ func _after_collision():
|
|||
# Unfreezes the ball and apply the bounced captured velocity to it
|
||||
freeze = false
|
||||
linear_velocity = bounced_velocity
|
||||
|
||||
|
||||
### DEBUG
|
||||
# freeze = true
|
||||
# queue_free()
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
[gd_scene load_steps=6 format=3 uid="uid://rdlvlyf0l1l"]
|
||||
[gd_scene load_steps=7 format=3 uid="uid://rdlvlyf0l1l"]
|
||||
|
||||
[ext_resource type="Script" path="res://Ball/ball.gd" id="1_oenn5"]
|
||||
[ext_resource type="PackedScene" uid="uid://lge7m41oi6pn" path="res://Ball/Meshes/ball_bouncing.glb" id="2_ccq7m"]
|
||||
[ext_resource type="PackedScene" uid="uid://b1embyb2knvho" path="res://Ball/Meshes/ball_flying.glb" id="4_fh5j8"]
|
||||
[ext_resource type="Script" path="res://Ball/ball_meshes.gd" id="4_llldm"]
|
||||
[ext_resource type="Script" path="res://Ball/ball_random_vector_node.gd" id="5_j25qm"]
|
||||
|
||||
[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
|
||||
contact_monitor = true
|
||||
can_sleep = false
|
||||
|
@ -27,10 +29,17 @@ one_shot = true
|
|||
[node name="Meshes" type="Node3D" parent="."]
|
||||
script = ExtResource("4_llldm")
|
||||
|
||||
[node name="DirectionNode" type="Node3D" parent="Meshes"]
|
||||
|
||||
[node name="RotationNode" type="Node3D" parent="Meshes"]
|
||||
|
||||
[node name="BallBouncingMesh" parent="Meshes" instance=ExtResource("2_ccq7m")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.3)
|
||||
visible = false
|
||||
|
||||
[node name="BallFlyingMesh" parent="Meshes" instance=ExtResource("4_fh5j8")]
|
||||
|
||||
[node name="RandomVectorNode" type="Node3D" parent="."]
|
||||
script = ExtResource("5_j25qm")
|
||||
|
||||
[node name="VectorPosition" type="Node3D" parent="RandomVectorNode"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -1)
|
||||
|
|
|
@ -10,10 +10,6 @@ var is_bouncing = false
|
|||
var max_squish_xy = 0.5 # Starts at 0
|
||||
var max_squish_z = 0.8 # From 0 to 1
|
||||
|
||||
# Apply a small offset to the up vector in the look_at function to fix it
|
||||
# not working when the target is perfectly aligned with the up vector
|
||||
const LOOK_AT_OFFSET_FIX = Vector3(0.01, 1, 0.01)
|
||||
|
||||
|
||||
func _ready():
|
||||
ball.ball_collision_started.connect(_on_collision)
|
||||
|
@ -21,16 +17,16 @@ func _ready():
|
|||
|
||||
|
||||
func _process(delta):
|
||||
_align_mesh_to_direction()
|
||||
_align_flying_mesh_to_direction()
|
||||
_squish_animation()
|
||||
|
||||
|
||||
func _align_mesh_to_direction():
|
||||
# Align the RotationNode to the movement direction
|
||||
$RotationNode.look_at(ball.captured_velocity + ball.global_position, LOOK_AT_OFFSET_FIX)
|
||||
func _align_flying_mesh_to_direction():
|
||||
# Align the DirectionNode to the movement direction
|
||||
$DirectionNode.look_at(ball.captured_velocity + ball.global_position, Utilities.LOOK_AT_OFFSET_FIX)
|
||||
|
||||
# Convert the rotation euler into a quaternion
|
||||
var euler_rotation = $RotationNode.rotation
|
||||
var euler_rotation = $DirectionNode.rotation
|
||||
var quaternion_rotation : Quaternion
|
||||
quaternion_rotation = quaternion_rotation.from_euler(euler_rotation)
|
||||
|
||||
|
@ -43,17 +39,30 @@ func _on_collision():
|
|||
$BallBouncingMesh.visible = true
|
||||
is_bouncing = true
|
||||
|
||||
# Align the Meshes node to the surface normal so the bouncing mesh is properly aligned
|
||||
look_at(ball.collision_normal + ball.global_position, LOOK_AT_OFFSET_FIX)
|
||||
_align_bouncing_mesh_to_surface()
|
||||
|
||||
|
||||
func _after_collision():
|
||||
$BallFlyingMesh.visible = true
|
||||
$BallBouncingMesh.visible = false
|
||||
is_bouncing = false
|
||||
|
||||
|
||||
func _align_bouncing_mesh_to_surface():
|
||||
# Align position to the surface
|
||||
var bone_position = ball.collision_position - ball.global_position
|
||||
skeleton_bouncing.set_bone_pose_position(1, bone_position)
|
||||
|
||||
# Reset the Meshes node rotation
|
||||
rotation = Vector3.ZERO
|
||||
# Align rotation to the surface normal
|
||||
$RotationNode.look_at(ball.collision_normal + ball.global_position, Utilities.LOOK_AT_OFFSET_FIX)
|
||||
|
||||
# Convert the rotation euler into a quaternion
|
||||
var euler_rotation = $RotationNode.rotation
|
||||
var quaternion_rotation : Quaternion
|
||||
quaternion_rotation = quaternion_rotation.from_euler(euler_rotation)
|
||||
|
||||
# Rotate the bone
|
||||
skeleton_bouncing.set_bone_pose_rotation(1, quaternion_rotation)
|
||||
|
||||
|
||||
func _squish_animation():
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
extends Node3D
|
||||
|
||||
@onready var ball = owner
|
||||
|
||||
var random_offset : Vector3
|
||||
|
||||
|
||||
func _ready():
|
||||
ball.ball_collision_started.connect(_get_random_offset)
|
||||
|
||||
|
||||
func _get_random_offset():
|
||||
# Align rotation to collision normal
|
||||
look_at(ball.collision_normal + ball.global_position, Utilities.LOOK_AT_OFFSET_FIX)
|
||||
|
||||
# Compose a random vector
|
||||
var x = randf_range(-0.5, 0.5)
|
||||
var y = randf_range(-0.5, 0.5)
|
||||
var z = randf_range(0, 1)
|
||||
var random_vector = Vector3(x, y, z)
|
||||
|
||||
$VectorPosition.position += random_vector
|
||||
random_offset = $VectorPosition.position
|
|
@ -1,20 +0,0 @@
|
|||
extends Node3D
|
||||
|
||||
|
||||
@onready var ball = owner
|
||||
@onready var mesh = get_node("tail")
|
||||
|
||||
|
||||
func _process(delta):
|
||||
# Align the tail to the linear velocity
|
||||
look_at(ball.linear_velocity + ball.global_position)
|
||||
|
||||
shrink_tail()
|
||||
|
||||
|
||||
func shrink_tail():
|
||||
# Set the blend shape value to how much the ball is squished
|
||||
# A power of 0.5 makes the shrinking effect more apparent
|
||||
var factor = pow((1 - ball.mesh.scale.z), 0.5)
|
||||
var blend_shape = mesh.find_blend_shape_by_name("Shrink")
|
||||
mesh.set_blend_shape_value(blend_shape, factor)
|
|
@ -1,45 +0,0 @@
|
|||
extends RigidBody3D
|
||||
|
||||
@onready var mesh = $BallMesh
|
||||
@onready var body = $BallBody
|
||||
@onready var body_anchor = $AnchorBody
|
||||
|
||||
@export var speed : float
|
||||
@export var gravity : Vector3
|
||||
@export var stiffness : float
|
||||
|
||||
|
||||
func _ready():
|
||||
linear_velocity = linear_velocity.normalized() * speed
|
||||
|
||||
# DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)
|
||||
|
||||
|
||||
func _physics_process(delta):
|
||||
if global_position.length() >= 100:
|
||||
print("ball escaped")
|
||||
queue_free()
|
||||
|
||||
# Visual
|
||||
var collision : KinematicCollision3D = body.move_and_collide(linear_velocity * delta, true)
|
||||
if collision:
|
||||
var collision_position = collision.get_position()
|
||||
mesh.look_at(collision_position, Vector3.UP)
|
||||
|
||||
if collision.get_collider().owner.is_in_group("balls"):
|
||||
mesh.scale.z = (global_position - collision.get_collider().global_position).length()
|
||||
else:
|
||||
mesh.scale.z = (collision_position - global_position).length() * 2
|
||||
var scalexy = clamp(sqrt(1 / mesh.scale.z), 0.0, 2.0)
|
||||
mesh.scale.x = scalexy
|
||||
mesh.scale.y = scalexy
|
||||
else:
|
||||
mesh.scale = Vector3.ONE
|
||||
|
||||
# Physics
|
||||
body_anchor.velocity = (global_position - body_anchor.global_position).normalized() * speed
|
||||
if not body_anchor.move_and_slide():
|
||||
body_anchor.global_position = global_position
|
||||
|
||||
constant_force = gravity + (body_anchor.global_position - global_position) * stiffness * pow(speed, 2)
|
||||
linear_velocity = linear_velocity.normalized() * clamp(linear_velocity.length(), 0, speed)
|
|
@ -1,55 +0,0 @@
|
|||
[gd_scene load_steps=9 format=3 uid="uid://dd1e3u5cyy3mk"]
|
||||
|
||||
[ext_resource type="Material" uid="uid://ccktnp41cys0r" path="res://Ball/Meshes/ball_material.tres" id="1_5n3i6"]
|
||||
[ext_resource type="Script" path="res://Ball/ball_test.gd" id="1_s3xmr"]
|
||||
[ext_resource type="PackedScene" uid="uid://ctsvwwopru2jf" path="res://Ball/Meshes/ball_tail.glb" id="3_s5l2d"]
|
||||
[ext_resource type="Script" path="res://Ball/ball_tail_mesh.gd" id="4_vur1t"]
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_jblqj"]
|
||||
radius = 0.1
|
||||
|
||||
[sub_resource type="SphereMesh" id="SphereMesh_52mtx"]
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_862wy"]
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_dwt7q"]
|
||||
|
||||
[node name="BallBase" type="RigidBody3D" groups=["balls"]]
|
||||
collision_layer = 0
|
||||
collision_mask = 0
|
||||
gravity_scale = 0.0
|
||||
lock_rotation = true
|
||||
linear_damp_mode = 1
|
||||
angular_damp_mode = 1
|
||||
script = ExtResource("1_s3xmr")
|
||||
speed = 5.0
|
||||
gravity = Vector3(0, -1, 0)
|
||||
stiffness = 5.0
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
shape = SubResource("SphereShape3D_jblqj")
|
||||
|
||||
[node name="BallMesh" type="MeshInstance3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.0029127)
|
||||
mesh = SubResource("SphereMesh_52mtx")
|
||||
surface_material_override/0 = ExtResource("1_5n3i6")
|
||||
|
||||
[node name="TailMesh" parent="BallMesh" instance=ExtResource("3_s5l2d")]
|
||||
script = ExtResource("4_vur1t")
|
||||
|
||||
[node name="BallBody" type="StaticBody3D" parent="."]
|
||||
collision_layer = 4
|
||||
collision_mask = 5
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="BallBody"]
|
||||
shape = SubResource("SphereShape3D_862wy")
|
||||
|
||||
[node name="AnchorBody" type="CharacterBody3D" parent="."]
|
||||
top_level = true
|
||||
collision_layer = 8
|
||||
collision_mask = 9
|
||||
motion_mode = 1
|
||||
wall_min_slide_angle = 0.0
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="AnchorBody"]
|
||||
shape = SubResource("SphereShape3D_dwt7q")
|
|
@ -1,7 +1,7 @@
|
|||
extends CharacterBody3D
|
||||
|
||||
|
||||
const SPEED = 10.0
|
||||
const SPEED = 5.0
|
||||
const JUMP_VELOCITY = 4.5
|
||||
|
||||
# Get the gravity from the project settings to be synced with RigidBody nodes.
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
[ext_resource type="Script" path="res://Player/player.gd" id="1_f70jf"]
|
||||
[ext_resource type="Script" path="res://Player/player_camera_basis.gd" id="2_o7m3c"]
|
||||
[ext_resource type="Script" path="res://Player/shooter.gd" id="3_eijnn"]
|
||||
[ext_resource type="PackedScene" uid="uid://dd1e3u5cyy3mk" path="res://Ball/ball_test.tscn" id="4_rdfyn"]
|
||||
[ext_resource type="PackedScene" uid="uid://rdlvlyf0l1l" path="res://Ball/ball.tscn" id="4_5tvf6"]
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_v066f"]
|
||||
radius = 0.35
|
||||
|
@ -31,4 +31,4 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -1)
|
|||
[node name="Shooter" type="Node3D" parent="Camera"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.5)
|
||||
script = ExtResource("3_eijnn")
|
||||
ball_scene = ExtResource("4_rdfyn")
|
||||
ball_scene = ExtResource("4_5tvf6")
|
||||
|
|
|
@ -2,12 +2,9 @@ extends Node3D
|
|||
|
||||
|
||||
@export var ball_scene : PackedScene
|
||||
var count = 0
|
||||
|
||||
|
||||
func shoot(spawn_position ,direction = Vector3.FORWARD, strength = 7):
|
||||
count += 1
|
||||
print(count)
|
||||
var ball = ball_scene.instantiate()
|
||||
|
||||
ball.linear_velocity = direction * strength
|
||||
|
|
|
@ -1,62 +0,0 @@
|
|||
[gd_scene load_steps=8 format=3 uid="uid://b06nx3ofndgjy"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://onahsd5he406" path="res://64x64_orange_grey.png" id="1_4apc2"]
|
||||
[ext_resource type="PackedScene" uid="uid://ggl4tqcb5dbc" path="res://Player/player.tscn" id="1_n0nhi"]
|
||||
[ext_resource type="Script" path="res://Misc/debug_cone.gd" id="3_nsiny"]
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_bwr1w"]
|
||||
albedo_texture = ExtResource("1_4apc2")
|
||||
uv1_scale = Vector3(0.5, 0.5, 0.5)
|
||||
uv1_triplanar = true
|
||||
texture_filter = 2
|
||||
|
||||
[sub_resource type="PlaneMesh" id="PlaneMesh_6jpek"]
|
||||
size = Vector2(3, 8)
|
||||
|
||||
[sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_iauoa"]
|
||||
points = PackedVector3Array(1.5, 0, 4, -1.5, 0, 4, 1.5, 0, -4, -1.5, 0, -4)
|
||||
|
||||
[sub_resource type="CylinderMesh" id="CylinderMesh_modx0"]
|
||||
top_radius = 0.0
|
||||
bottom_radius = 0.3
|
||||
height = 0.6
|
||||
|
||||
[node name="World" type="Node3D"]
|
||||
|
||||
[node name="Level" type="Node3D" parent="."]
|
||||
|
||||
[node name="CSGBox3D" type="CSGBox3D" parent="Level"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 4, 0)
|
||||
material_override = SubResource("StandardMaterial3D_bwr1w")
|
||||
use_collision = true
|
||||
size = Vector3(12, 8, 12)
|
||||
|
||||
[node name="CSGBox3D2" type="CSGBox3D" parent="Level/CSGBox3D"]
|
||||
operation = 2
|
||||
size = Vector3(11.8, 7.8, 11.8)
|
||||
|
||||
[node name="DiagonalWall" type="StaticBody3D" parent="Level"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -5, 0, -5)
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="Level/DiagonalWall"]
|
||||
transform = Transform3D(0.707107, 0.707107, -3.09086e-08, 0, -4.37114e-08, -1, -0.707107, 0.707107, -3.09086e-08, 0, 4, 0)
|
||||
mesh = SubResource("PlaneMesh_6jpek")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="Level/DiagonalWall"]
|
||||
transform = Transform3D(0.707107, 0.707107, -3.09086e-08, 0, -4.37114e-08, -1, -0.707107, 0.707107, -3.09086e-08, 0, 4, 0)
|
||||
shape = SubResource("ConvexPolygonShape3D_iauoa")
|
||||
|
||||
[node name="Player" parent="." instance=ExtResource("1_n0nhi")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.2, 0)
|
||||
|
||||
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
|
||||
transform = Transform3D(0.482579, -0.637736, -0.600342, 0, -0.685437, 0.728132, -0.875852, -0.351381, -0.330778, 0, 0, 0)
|
||||
|
||||
[node name="DebugCone" type="Node3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -4.5, 0.5, 4.5)
|
||||
script = ExtResource("3_nsiny")
|
||||
|
||||
[node name="DebugConeMesh" type="MeshInstance3D" parent="DebugCone"]
|
||||
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 0, 0)
|
||||
mesh = SubResource("CylinderMesh_modx0")
|
||||
skeleton = NodePath("../..")
|
|
@ -1,11 +1,10 @@
|
|||
[gd_scene load_steps=11 format=3 uid="uid://b06nx3ofndgjy"]
|
||||
[gd_scene load_steps=10 format=3 uid="uid://b06nx3ofndgjy"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://onahsd5he406" path="res://Misc/64x64_orange_grey.png" id="1_k0u6d"]
|
||||
[ext_resource type="PackedScene" uid="uid://ggl4tqcb5dbc" path="res://Player/player.tscn" id="1_n0nhi"]
|
||||
[ext_resource type="Script" path="res://Misc/debug_cone.gd" id="3_nsiny"]
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_bwr1w"]
|
||||
albedo_color = Color(1, 1, 1, 0.882353)
|
||||
albedo_texture = ExtResource("1_k0u6d")
|
||||
uv1_scale = Vector3(0.5, 0.5, 0.5)
|
||||
uv1_triplanar = true
|
||||
|
@ -21,10 +20,6 @@ points = PackedVector3Array(1.5, 0, 4, -1.5, 0, 4, 1.5, 0, -4, -1.5, 0, -4)
|
|||
radius = 3.0
|
||||
height = 6.0
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_587aa"]
|
||||
transparency = 1
|
||||
albedo_color = Color(0.619608, 1, 0.67451, 0.678431)
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_hjh1m"]
|
||||
radius = 3.0
|
||||
|
||||
|
@ -59,11 +54,10 @@ transform = Transform3D(0.707107, 0.707107, -3.09086e-08, 0, -4.37114e-08, -1, -
|
|||
shape = SubResource("ConvexPolygonShape3D_iauoa")
|
||||
|
||||
[node name="Sphere" type="StaticBody3D" parent="Level"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.736659, 2.85172, -3.29585)
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 6, 0, -6)
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="Level/Sphere"]
|
||||
mesh = SubResource("SphereMesh_0a0pq")
|
||||
surface_material_override/0 = SubResource("StandardMaterial3D_587aa")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="Level/Sphere"]
|
||||
shape = SubResource("SphereShape3D_hjh1m")
|
||||
|
|
|
@ -15,6 +15,11 @@ run/main_scene="res://World/world.tscn"
|
|||
config/features=PackedStringArray("4.1", "Forward Plus")
|
||||
config/icon="res://icon.svg"
|
||||
|
||||
[autoload]
|
||||
|
||||
Utilities="*res://Autoload/Utilities.gd"
|
||||
Debug="*res://Autoload/Debug.gd"
|
||||
|
||||
[input]
|
||||
|
||||
move_left={
|
||||
|
@ -48,10 +53,19 @@ 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)
|
||||
]
|
||||
}
|
||||
debug_2={
|
||||
"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":50,"key_label":0,"unicode":50,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[layer_names]
|
||||
|
||||
3d_physics/layer_1="general"
|
||||
3d_physics/layer_2="player"
|
||||
3d_physics/layer_3="balls"
|
||||
3d_physics/layer_4="anchors"
|
||||
|
|
Loading…
Reference in New Issue