From 88fdf66db3dfc1c761860f1b18254a239e0e64e6 Mon Sep 17 00:00:00 2001 From: cel Date: Sun, 17 Jul 2022 07:11:45 +0100 Subject: fix ball bug --- godot/scenes/Die.gd | 48 +++++++++++++++++++++++++----------- godot/scenes/Die.tscn | 8 ++++-- godot/scenes/levels/MainMenu.tscn | 52 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 91 insertions(+), 17 deletions(-) (limited to 'godot/scenes') diff --git a/godot/scenes/Die.gd b/godot/scenes/Die.gd index 76c1474..1f82417 100644 --- a/godot/scenes/Die.gd +++ b/godot/scenes/Die.gd @@ -15,12 +15,12 @@ var die_launch_force_magnitude = 0 var die_launch_force_direction = Vector3(0,0,0) var die_launch_force = Vector3(0,0,0) var die_launch_force_multiplier = 0.05 -var die_launch_force_magnitude_max = 500 +var die_launch_force_magnitude_max = 1000 var left_pressed = false - var mat -var target_bounce = 1 -var previous_bounciness = 0 +var target_bounce = 10 +var default_gravity = 2 +var default_bounciness = 0 var curr_buff = buff.none @@ -31,6 +31,7 @@ enum buff { stroke, bounce, phase, + gravity, ball } @@ -41,7 +42,8 @@ func _ready(): $CamRoot.set_as_toplevel(true) _game = get_node("/root/Game") mat = get_physics_material_override() - previous_bounciness = mat.get_bounce() + mat.friction = 1 + gravity_scale = default_gravity $PowerUI/PowerBar.hide() $PowerUI/PowerBar.max_value = die_launch_force_magnitude_max @@ -77,6 +79,8 @@ func _input(event): die_launch_force_direction = -die_launch_force_direction.z die_launch_force = die_launch_force_direction * clamp(die_launch_force_magnitude, 0, die_launch_force_magnitude_max) * die_launch_force_multiplier self.apply_central_impulse(die_launch_force) + if curr_buff != buff.ball: + self.apply_torque_impulse(die_launch_force) $PowerUI/PowerBar.hide() _game.add_stroke() #Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) @@ -101,13 +105,14 @@ func _physics_process(delta): $CamRoot.translation.y = translation.y + 5 $CamRoot.translation.z = translation.z - if dice_is_moving == true and angular_velocity.length() < 0.01 and linear_velocity.length() < 0.01: - dice_is_moving = false + if dice_is_moving == true and angular_velocity.length() < 0.1 and linear_velocity.length() < 0.1: + if curr_buff != buff.ball: + dice_is_moving = false revert_current_buff() curr_buff = get_buff_from_upwards_side() apply_buff() - elif dice_is_moving == false and angular_velocity.length() >= 0.01 and linear_velocity.length() >= 0.01: + elif dice_is_moving == false and angular_velocity.length() >= 0.1 and linear_velocity.length() >= 0.1: dice_is_moving = true @@ -120,29 +125,37 @@ func _physics_process(delta): BUFFS """ +func is_on_side(): + if $Plus1.get_overlapping_areas().size() > 0 || $Plus2.get_overlapping_areas().size() > 0 || $Ball1.get_overlapping_areas().size() > 0 || $Ball2.get_overlapping_areas().size() > 0 || $Bounce1.get_overlapping_areas().size() > 0 || $Bounce2.get_overlapping_areas().size() > 0 || $Phase1.get_overlapping_areas().size() > 0 || $Phase2.get_overlapping_areas().size() > 0: + return true + else: + return false + func get_buff_from_upwards_side(): if $Plus1.get_overlapping_areas().size() > 0 || $Plus2.get_overlapping_areas().size() > 0: return buff.stroke if $Ball1.get_overlapping_areas().size() > 0 || $Ball2.get_overlapping_areas().size() > 0: return buff.ball if $Bounce1.get_overlapping_areas().size() > 0 || $Bounce2.get_overlapping_areas().size() > 0: - return buff.bounce + return buff.gravity if $Phase1.get_overlapping_areas().size() > 0 || $Phase2.get_overlapping_areas().size() > 0: return buff.phase return buff.none +func low_gravity(): + gravity_scale = 0.2 + func extra_stroke(): _game.revoke_stroke() - func bounciness(): - mat.set_bounce(target_bounce) + mat.bounce = target_bounce func bounciness_revert(): - mat.set_bounce(previous_bounciness) + mat.bounce = default_bounciness func phase(): @@ -157,6 +170,8 @@ func ball(): $BallShape.show() $BallShape.set_process(true) $BallShape.disabled = false + angular_velocity = Vector3(0,0,0) + linear_velocity = Vector3(0,0,0) func ball_revert(): @@ -165,6 +180,7 @@ func ball_revert(): $BallShape.disabled = true + func revert_current_buff(): match curr_buff: buff.ball: @@ -173,15 +189,19 @@ func revert_current_buff(): bounciness_revert() buff.phase: phase_revert() - + buff.gravity: + gravity_scale = default_gravity func apply_buff(): match curr_buff: buff.ball: + gravity_scale = default_gravity ball() buff.bounce: + gravity_scale = default_gravity bounciness() buff.phase: phase() + gravity_scale = default_gravity buff.stroke: - extra_stroke() + low_gravity() diff --git a/godot/scenes/Die.tscn b/godot/scenes/Die.tscn index 2afc4f3..bab53ad 100644 --- a/godot/scenes/Die.tscn +++ b/godot/scenes/Die.tscn @@ -3,7 +3,8 @@ [ext_resource path="res://scenes/Die.gd" type="Script" id=1] [ext_resource path="res://assets/game_objects/W8baseColor_Mat.material" type="Material" id=2] -[sub_resource type="PhysicsMaterial" id=3] +[sub_resource type="PhysicsMaterial" id=7] +friction = 0.0 [sub_resource type="ConvexPolygonShape" id=2] points = PoolVector3Array( -0.0850063, -0.879389, -0.0282584, 0.0288993, 0.929375, 0.0289349, 0.0288993, 0.929375, -0.0289349, 0.929367, -0.0289314, 0.0289314, -0.0289784, -0.0289338, 0.929338, -0.929369, 0.028929, 0.028929, 0.0288993, -0.0289349, -0.929375, 0.0288993, -0.929375, 0.0289349, -0.0850063, 0.0282584, -0.879389, 0.0282247, 0.084959, 0.87945, 0.857489, 0.056933, -0.0855785, -0.879454, -0.0849424, 0.0282549, 0.0570775, -0.885814, -0.0571088, 0.0570775, -0.0571088, 0.885814, -0.0571532, 0.885743, -0.0571043, -0.0571532, 0.885743, 0.0571043, 0.0570775, 0.0571088, -0.885814, -0.885806, -0.057097, -0.057097, 0.879446, 0.0849494, 0.0282572, 0.857335, -0.0571018, -0.0855632, -0.0571532, 0.0571043, 0.885743, -0.0571532, -0.885743, 0.0571043, -0.885806, 0.057097, -0.057097, -0.0571532, -0.0571043, -0.885743, 0.0570775, 0.0571088, 0.885814, -0.0571532, -0.885743, -0.0571043, -0.0571532, 0.0571043, -0.885743, 0.0570775, -0.885814, 0.0571088, 0.0570775, 0.885814, 0.0571088, -0.0571532, -0.0571043, 0.885743, -0.885806, 0.057097, 0.057097, 0.0570775, 0.885814, -0.0571088, 0.0570775, -0.0571088, -0.885814, 0.857335, -0.0571018, 0.0855632, -0.885806, -0.057097, 0.057097, 0.857489, 0.056933, 0.0855785, 0.929425, 0.0287513, -0.0289333, 0.929367, -0.0289314, -0.0289314, -0.0289784, 0.929338, -0.0289338, 0.0288993, 0.0289349, -0.929375, -0.929369, -0.028929, -0.028929, -0.0283039, -0.87942, -0.0849561, 0.084933, 0.0282608, 0.879461, -0.0289784, 0.929338, 0.0289338, -0.0289784, -0.0289338, -0.929338, -0.0289784, 0.0289338, 0.929338, 0.0288993, -0.0289349, 0.929375, 0.0288993, -0.929375, -0.0289349, -0.0289784, -0.929338, 0.0289338, -0.929369, 0.028929, -0.028929, -0.0283039, 0.0849561, -0.87942, -0.879454, -0.0282549, 0.0849424, 0.879512, 0.0280816, 0.0849558, 0.879446, -0.0849494, -0.0282572, -0.0282988, -0.822574, 0.141805, 0.17021, 0.0280745, -0.794261, -0.879454, 0.0849424, -0.0282549, -0.0283039, 0.87942, 0.0849561, 0.0282247, 0.87945, -0.084959, 0.0282247, -0.084959, -0.87945, -0.879454, -0.0282549, -0.0849424, -0.0850063, 0.0282584, 0.879389, -0.0850063, 0.879389, 0.0282584, 0.084933, -0.0282608, 0.879461 ) @@ -32,7 +33,10 @@ radius = 0.1 [node name="Die" type="RigidBody"] collision_mask = 3 -physics_material_override = SubResource( 3 ) +physics_material_override = SubResource( 7 ) +linear_damp = 0.0 +angular_velocity = Vector3( 0, 0, 0.009 ) +angular_damp = 1.5 script = ExtResource( 1 ) [node name="CollisionShape" type="CollisionShape" parent="."] diff --git a/godot/scenes/levels/MainMenu.tscn b/godot/scenes/levels/MainMenu.tscn index a91b3fa..b06a027 100644 --- a/godot/scenes/levels/MainMenu.tscn +++ b/godot/scenes/levels/MainMenu.tscn @@ -1,10 +1,54 @@ -[gd_scene load_steps=5 format=2] +[gd_scene load_steps=10 format=2] [ext_resource path="res://scenes/Menu.tscn" type="PackedScene" id=1] [ext_resource path="res://assets/game_objects/W8.gltf" type="PackedScene" id=2] [ext_resource path="res://scenes/Rotator.gd" type="Script" id=3] [ext_resource path="res://assets/sounds/main_menu.mp3" type="AudioStream" id=4] +[sub_resource type="VisualShaderNodeColorConstant" id=2] +constant = Color( 0.0428785, 0.101562, 0.0362446, 1 ) + +[sub_resource type="VisualShader" id=3] +code = "shader_type spatial; +render_mode specular_schlick_ggx; + + + + +void vertex() { +// Output:0 + +} + +void fragment() { +// Color:2 + vec3 n_out2p0 = vec3(0.042878, 0.101562, 0.036245); + float n_out2p1 = 1.000000; + +// Output:0 + ALBEDO = n_out2p0; + +} + +void light() { +// Output:0 + +} +" +graph_offset = Vector2( 0, 75 ) +nodes/fragment/0/position = Vector2( 660, 200 ) +nodes/fragment/2/node = SubResource( 2 ) +nodes/fragment/2/position = Vector2( 240, 280 ) +nodes/fragment/connections = PoolIntArray( 2, 0, 0, 0 ) + +[sub_resource type="ShaderMaterial" id=4] +shader = SubResource( 3 ) + +[sub_resource type="PlaneMesh" id=1] +material = SubResource( 4 ) + +[sub_resource type="Skin" id=5] + [node name="MainMenu" type="Spatial"] [node name="Menu" parent="." instance=ExtResource( 1 )] @@ -18,3 +62,9 @@ transform = Transform( 1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 5, 0 [node name="AudioStreamPlayer2D" type="AudioStreamPlayer2D" parent="."] stream = ExtResource( 4 ) autoplay = true + +[node name="Background" type="MeshInstance" parent="."] +transform = Transform( 10, 0, 0, 0, 1, 0, 0, 0, 10, 0, -3.21632, 0 ) +mesh = SubResource( 1 ) +skin = SubResource( 5 ) +material/0 = null -- cgit