Magnetic effect is sticky like plasma ball

This commit is contained in:
Rob Kelly 2024-12-04 17:59:44 -07:00
parent fb19b1a1ad
commit ce6c9b3aac
6 changed files with 30 additions and 46 deletions

View File

@ -13,14 +13,11 @@ enum Type {
const TERRAIN_DAMPING_EPSILON := 1e-6
const MAGNUS_EPSILON := 1e-3
const IRON_DAMPING := 9999.0
## Angular damping while in air
@export var air_damping := 0.0
## Angular damping while in collision with rough terrain
@export var rough_damping := 8.0
## Angular damping for iron balls
@export var iron_damping := 9999.0
#@export var fluid_density := 1.225
#@export var lift_coefficient := 0.05
@ -32,14 +29,8 @@ const IRON_DAMPING := 9999.0
## and `r` is the radius of the ball, which is 5cm.
@export var magnus_coefficient := 0.00024
## Causes the ball to act more like a brick
@export var iron_ball := false:
set(value):
if value:
physics_material_override = iron_physics
else:
physics_material_override = normal_physics
iron_ball = value
## Causes the ball to stick to surfaces
@export var magnetic := false
## Base damage inflicted on impact with a player
@export var base_damage := 15.0
@ -52,18 +43,21 @@ var _position_on_last_wake: Vector3
var _awake := false
var _zones: Array[BallZone] = []
@onready var manual_sleep_timer: Timer = %ManualSleepTimer
@onready var sfx: BallSFX = %SFX
@onready var normal_physics: PhysicsMaterial = preload(
"res://src/equipment/balls/physics_ball/normal_physics.tres"
)
@onready var iron_physics: PhysicsMaterial = preload(
"res://src/equipment/balls/physics_ball/iron_physics.tres"
)
@onready var _debug_draw: Control = %DebugDraw
## Should this ball stick to surfaces, rather than bounce?
func is_sticky() -> bool:
return magnetic
## Called by a water area when this ball enters it
func enter_water() -> void:
entered_water.emit()
@ -108,8 +102,6 @@ func _integrate_forces(state: PhysicsDirectBodyState3D) -> void:
damping = _total_terrain_angular_damping()
if damping <= TERRAIN_DAMPING_EPSILON:
damping = rough_damping
if iron_ball:
damping = iron_damping
angular_damp = damping
@ -147,6 +139,11 @@ func _on_sleeping_state_changed() -> void:
func _on_collision(body: Node) -> void:
if is_sticky():
# Freeze physics as soon as we hit something
freeze = true
manual_sleep_timer.start()
if body is Terrain3D:
sfx.play_sfx(Terrain.at_position(global_position, body as Terrain3D))
elif body is CSGShape3D:
@ -155,3 +152,8 @@ func _on_collision(body: Node) -> void:
sfx.play_sfx(Terrain.from_physical_layer((body as CollisionObject3D).collision_layer))
else:
print_debug("COLLIDER: ", body)
func _fire_sleep_signal() -> void:
sleeping = true
sleeping_state_changed.emit()

View File

@ -1,7 +0,0 @@
[gd_resource type="PhysicsMaterial" format=3 uid="uid://cfd56nhaods5a"]
[resource]
friction = 0.8
rough = true
bounce = 1.0
absorbent = true

View File

@ -103,7 +103,6 @@ linear_damp_mode = 1
angular_damp_mode = 1
angular_damp = 8.0
script = ExtResource("1_iwh2u")
iron_damping = 1e+07
[node name="BallMesh" type="MeshInstance3D" parent="."]
mesh = SubResource("SphereMesh_y0d13")
@ -146,5 +145,10 @@ unit_size = 40.0
max_db = 0.0
bus = &"SFX"
[node name="ManualSleepTimer" type="Timer" parent="."]
unique_name_in_owner = true
one_shot = true
[connection signal="body_entered" from="." to="." method="_on_collision"]
[connection signal="sleeping_state_changed" from="." to="." method="_on_sleeping_state_changed"]
[connection signal="timeout" from="ManualSleepTimer" to="." method="_fire_sleep_signal"]

View File

@ -1,16 +1,6 @@
extends GameBall
## The plasma ball sticks to the first surface it hits
@onready var manual_sleep_timer: Timer = %ManualSleepTimer
## Plasma ball always sticks to surfaces
func _on_body_entered(_body: Node) -> void:
print_debug("Plasma ball stuck to ", _body)
# Freeze physics as soon as we hit something
freeze = true
manual_sleep_timer.start()
func _fire_sleep_signal() -> void:
sleeping = true
sleeping_state_changed.emit()
func is_sticky() -> bool:
return true

View File

@ -2,7 +2,7 @@
[ext_resource type="PackedScene" uid="uid://dfttci386ohip" path="res://src/equipment/balls/physics_ball/physics_ball.tscn" id="1_yh4fp"]
[ext_resource type="Texture2D" uid="uid://c47bkx508biqr" path="res://assets/sprites/particles/plasma.png" id="2_8fdyx"]
[ext_resource type="Script" path="res://src/equipment/balls/plasma_ball/plasma_ball.gd" id="2_pdts3"]
[ext_resource type="Script" path="res://src/equipment/balls/plasma_ball/plasma_ball.gd" id="2_16fhh"]
[sub_resource type="Curve" id="Curve_kabhn"]
max_value = 2.0
@ -48,8 +48,8 @@ material = SubResource("StandardMaterial3D_7ptri")
size = Vector2(0.4, 0.4)
[node name="PlasmaBall" instance=ExtResource("1_yh4fp")]
script = ExtResource("2_pdts3")
base_damage = 30.0
script = ExtResource("2_16fhh")
magnetic = true
[node name="PlasmaFireEffect" type="GPUParticles3D" parent="BallMesh" index="0"]
amount = 20
@ -57,9 +57,4 @@ lifetime = 0.6
process_material = SubResource("ParticleProcessMaterial_uffe8")
draw_pass_1 = SubResource("QuadMesh_go8iw")
[node name="ManualSleepTimer" type="Timer" parent="." index="3"]
unique_name_in_owner = true
one_shot = true
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
[connection signal="timeout" from="ManualSleepTimer" to="." method="_fire_sleep_signal"]

View File

@ -272,7 +272,7 @@ func take_shot() -> void:
print_debug("Shot offset: ", offset, "; ", offset.length(), " m")
if game_ball:
game_ball.iron_ball = club_type == Club.Type.IRON
game_ball.magnetic = club_type == Club.Type.IRON
game_ball.freeze = false
game_ball.apply_impulse(impulse, offset)