make it easier to tell where the ball is going
This commit is contained in:
parent
5a768af1f3
commit
6a31ab76b8
7 changed files with 279 additions and 66 deletions
164
elements/gravity.tscn
Normal file
164
elements/gravity.tscn
Normal 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
35
elements/player.tscn
Normal 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="."]
|
|
@ -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")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue