make it easier to tell where the ball is going

This commit is contained in:
Taevas 2025-02-22 12:05:38 +01:00
parent 5a768af1f3
commit 6a31ab76b8
7 changed files with 279 additions and 66 deletions

164
elements/gravity.tscn Normal file
View file

@ -0,0 +1,164 @@
[gd_scene load_steps=7 format=3 uid="uid://dw0xl8644x166"]
[ext_resource type="Texture2D" uid="uid://ctjugvy1v3y6b" path="res://graphics/arrow.svg" id="1_4mbho"]
[sub_resource type="GDScript" id="GDScript_wuka5"]
script/source = "extends HSlider
# Maybe change it so it's not a slider, but just a value that... depends on the mouse position?
# Or a value that's only high if the user is pressing shift, à la catch the beat
func _on_value_changed(value: float) -> void:
PhysicsServer3D.area_set_param(get_viewport().find_world_3d().space, PhysicsServer3D.AREA_PARAM_GRAVITY, value)
func _on_focus_entered() -> void:
release_focus()
"
[sub_resource type="GDScript" id="GDScript_my602"]
script/source = "extends TextureRect
func _ready() -> void:
# set the indicator to be fully transparent when it first spawns
self.self_modulate = Color(1, 1, 1, 0)
func _input(ev: InputEvent) -> void:
if ev is InputEventKey and ev.is_pressed():
var k = ev.keycode
if k == KEY_UP or k == KEY_RIGHT or k == KEY_LEFT or k == KEY_DOWN:
var direction = Vector3()
if k == KEY_UP:
direction = Vector3.UP
self.rotation_degrees = -90
elif k == KEY_LEFT:
direction = Vector3.LEFT
self.rotation_degrees = -180
elif k == KEY_RIGHT:
direction = Vector3.RIGHT
self.rotation_degrees = 0
elif k == KEY_DOWN:
direction = Vector3.DOWN
self.rotation_degrees = 90
PhysicsServer3D.area_set_param(
get_viewport().find_world_3d().space,
PhysicsServer3D.AREA_PARAM_GRAVITY_VECTOR,
direction
)
if $AnimationPlayer.is_playing():
$AnimationPlayer.stop()
$AnimationPlayer.play(\"grow_fadeout\")
"
[sub_resource type="Animation" id="Animation_6rwl4"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:scale")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Vector2(0.3, 0.3)]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath(".:self_modulate")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Color(1, 1, 1, 0.501961)]
}
[sub_resource type="Animation" id="Animation_ll6d0"]
resource_name = "grow_fadeout"
length = 0.2
step = 0.2
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:scale")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.2),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Vector2(0.3, 0.3), Vector2(0.8, 0.8)]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath(".:self_modulate")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0, 0.142857),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Color(1, 1, 1, 0.501961), Color(1, 1, 1, 0)]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_0w0ne"]
_data = {
"RESET": SubResource("Animation_6rwl4"),
"grow_fadeout": SubResource("Animation_ll6d0")
}
[node name="Gravity" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="Strength" type="HSlider" parent="."]
layout_mode = 1
anchors_preset = -1
anchor_left = 0.2
anchor_top = 0.9
anchor_right = 0.8
anchor_bottom = 1.0
offset_right = -0.00012207
grow_horizontal = 2
grow_vertical = 0
size_flags_horizontal = 4
size_flags_vertical = 1
min_value = 10.0
max_value = 40.0
step = 0.2
value = 10.0
script = SubResource("GDScript_wuka5")
metadata/_edit_use_anchors_ = true
[node name="Direction" type="TextureRect" parent="."]
self_modulate = Color(1, 1, 1, 0.501961)
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
scale = Vector2(0.3, 0.3)
pivot_offset = Vector2(576, 324)
texture = ExtResource("1_4mbho")
expand_mode = 3
stretch_mode = 5
script = SubResource("GDScript_my602")
metadata/_edit_use_anchors_ = true
[node name="AnimationPlayer" type="AnimationPlayer" parent="Direction"]
libraries = {
"": SubResource("AnimationLibrary_0w0ne")
}
[connection signal="focus_entered" from="Strength" to="Strength" method="_on_focus_entered"]
[connection signal="value_changed" from="Strength" to="Strength" method="_on_value_changed"]

35
elements/player.tscn Normal file
View file

@ -0,0 +1,35 @@
[gd_scene load_steps=4 format=3 uid="uid://cnnvwotv33u1b"]
[ext_resource type="PackedScene" uid="uid://dw0xl8644x166" path="res://elements/gravity.tscn" id="1_h0h2o"]
[ext_resource type="PackedScene" uid="uid://df5m716pd6mej" path="res://elements/sphere.tscn" id="2_ophnk"]
[sub_resource type="GDScript" id="GDScript_bnqcw"]
script/source = "extends Node
func _process(delta: float) -> void:
## Keep the ball at the center of the camera, at a distance
$Camera.position = $Sphere.position + Vector3(0, 0, 20)
## Angle of the camera, so the player can see where the ball is going
var velocity: Vector3 = $Sphere.linear_velocity
var desired_x = max(min(velocity.y / 2, 20), -20)
var desired_y = max(min(-velocity.x / 2, 45), -45)
var difference_x = $Camera.rotation_degrees.x - desired_x
var difference_y = $Camera.rotation_degrees.y - desired_y
$Camera.rotation_degrees.x -= max(min(difference_x / 4, 3), -3)
$Camera.rotation_degrees.y -= max(min(difference_y / 4, 3), -3)
## FOV of the camera, so it unzooms more at higher velocities
const default_fov = 75
var total_velocity = abs(velocity.x) + abs(velocity.y)
$Camera.fov = default_fov + (total_velocity / 12)
"
[node name="Player" type="Node"]
script = SubResource("GDScript_bnqcw")
[node name="Gravity" parent="." instance=ExtResource("1_h0h2o")]
[node name="Sphere" parent="." instance=ExtResource("2_ophnk")]
[node name="Camera" type="Camera3D" parent="."]

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=7 format=3 uid="uid://df5m716pd6mej"]
[gd_scene load_steps=9 format=3 uid="uid://df5m716pd6mej"]
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_vumbr"]
bounce = 0.8
@ -85,6 +85,16 @@ fill_to = Vector2(0.504762, 1)
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_14eku"]
albedo_texture = SubResource("GradientTexture2D_vxsyc")
[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_4tofj"]
direction = Vector3(0, 0, 0)
gravity = Vector3(0, 0, 0)
[sub_resource type="SphereMesh" id="SphereMesh_1m3ut"]
radius = 0.2
height = 0.4
radial_segments = 8
rings = 4
[node name="Sphere" type="RigidBody3D"]
axis_lock_linear_z = true
physics_material_override = SubResource("PhysicsMaterial_vumbr")
@ -97,3 +107,8 @@ shape = SubResource("SphereShape3D_xfgrm")
radial_segments = 20
rings = 10
material = SubResource("StandardMaterial3D_14eku")
[node name="GPUParticles3D" type="GPUParticles3D" parent="."]
amount = 16
process_material = SubResource("ParticleProcessMaterial_4tofj")
draw_pass_1 = SubResource("SphereMesh_1m3ut")

9
graphics/arrow.svg Normal file
View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
<svg fill="#FFFFFF" height="800px" width="800px" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
viewBox="0 0 330 330" xml:space="preserve">
<path id="XMLID_222_" d="M250.606,154.389l-150-149.996c-5.857-5.858-15.355-5.858-21.213,0.001
c-5.857,5.858-5.857,15.355,0.001,21.213l139.393,139.39L79.393,304.394c-5.857,5.858-5.857,15.355,0.001,21.213
C82.322,328.536,86.161,330,90,330s7.678-1.464,10.607-4.394l149.999-150.004c2.814-2.813,4.394-6.628,4.394-10.606
C255,161.018,253.42,157.202,250.606,154.389z"/>
</svg>

After

Width:  |  Height:  |  Size: 697 B

37
graphics/arrow.svg.import Normal file
View file

@ -0,0 +1,37 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://ctjugvy1v3y6b"
path="res://.godot/imported/arrow.svg-920a87ad5eb67570115f11e52bd4e1ec.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://graphics/arrow.svg"
dest_files=["res://.godot/imported/arrow.svg-920a87ad5eb67570115f11e52bd4e1ec.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false

View file

@ -1,51 +1,25 @@
[gd_scene load_steps=4 format=3 uid="uid://ccgnnif026wb4"]
[gd_scene load_steps=5 format=3 uid="uid://ccgnnif026wb4"]
[ext_resource type="PackedScene" uid="uid://dujoplhd35kqg" path="res://level_base.tscn" id="1_ad0pp"]
[ext_resource type="PackedScene" uid="uid://gis4s061n422" path="res://elements/platform.tscn" id="2_g4sgl"]
[ext_resource type="PackedScene" uid="uid://dw0xl8644x166" path="res://elements/gravity.tscn" id="3_80ler"]
[sub_resource type="GDScript" id="GDScript_oxyvh"]
script/source = "extends Node
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
func _input(ev: InputEvent) -> void:
pass
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
#print($LevelBase/Sphere.position)
pass
func _on_h_slider_value_changed(value: float) -> void:
print(value)
PhysicsServer3D.area_set_param(get_viewport().find_world_3d().space, PhysicsServer3D.AREA_PARAM_GRAVITY, value)
func _unhandled_key_input(ev: InputEvent) -> void:
if ev is InputEventKey:
var k = ev.keycode
if k == KEY_UP or k == KEY_RIGHT or k == KEY_LEFT or k == KEY_DOWN:
var direction = Vector3()
if k == KEY_UP:
direction = Vector3.UP
elif k == KEY_LEFT:
direction = Vector3.LEFT
elif k == KEY_RIGHT:
direction = Vector3.RIGHT
elif k == KEY_DOWN:
direction = Vector3.DOWN
PhysicsServer3D.area_set_param(
get_viewport().find_world_3d().space,
PhysicsServer3D.AREA_PARAM_GRAVITY_VECTOR,
direction
)
print(\"direction is \", direction)
func _on_h_slider_focus_entered() -> void:
$HSlider.release_focus()
pass # Replace with function body.
# if ev is InputEventKey and ev.is_pressed():
# var k = ev.keycode
# if k == KEY_UP or k == KEY_RIGHT or k == KEY_LEFT or k == KEY_DOWN:
# if k == KEY_UP:
# $LevelBase/Camera3D.rotation_degrees = Vector3i(0, 0, 0)
# elif k == KEY_LEFT:
# $LevelBase/Camera3D.rotation_degrees = Vector3i(0, 10, 0)
# elif k == KEY_RIGHT:
# $LevelBase/Camera3D.rotation_degrees = Vector3i(0, -10, 0)
# elif k == KEY_DOWN:
# $LevelBase/Camera3D.rotation_degrees = Vector3i(-10, 0, 0)
"
[node name="Game" type="Node"]
@ -62,24 +36,6 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -42.8526, -13.7254, 0)
[node name="Platform3" parent="LevelBase" instance=ExtResource("2_g4sgl")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 44.7108, -13.7254, 0)
[node name="HSlider" type="HSlider" parent="."]
anchors_preset = -1
anchor_left = 0.2
anchor_top = 0.9
anchor_right = 0.8
anchor_bottom = 1.0
offset_right = -0.00012207
grow_horizontal = 2
grow_vertical = 0
size_flags_horizontal = 4
size_flags_vertical = 1
min_value = 10.0
max_value = 20.0
step = 0.2
value = 10.0
metadata/_edit_use_anchors_ = true
[connection signal="focus_entered" from="HSlider" to="." method="_on_h_slider_focus_entered"]
[connection signal="value_changed" from="HSlider" to="." method="_on_h_slider_value_changed"]
[node name="Gravity" parent="." instance=ExtResource("3_80ler")]
[editable path="LevelBase"]

View file

@ -1,6 +1,6 @@
[gd_scene load_steps=6 format=3 uid="uid://dujoplhd35kqg"]
[ext_resource type="PackedScene" uid="uid://df5m716pd6mej" path="res://elements/sphere.tscn" id="1_8mffa"]
[ext_resource type="PackedScene" uid="uid://cnnvwotv33u1b" path="res://elements/player.tscn" id="1_ykskn"]
[sub_resource type="GDScript" id="GDScript_hbi5e"]
script/source = "extends Node3D
@ -13,7 +13,7 @@ func _ready() -> void:
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
$Camera3D.position = $Sphere.position + Vector3(0, 0, 20)
pass
"
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_6pkua"]
@ -36,7 +36,4 @@ script = SubResource("GDScript_hbi5e")
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource("Environment_jfl74")
[node name="Sphere" parent="." instance=ExtResource("1_8mffa")]
[node name="Camera3D" type="Camera3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.534398)
[node name="Player" parent="." instance=ExtResource("1_ykskn")]