Compare commits

..

2 Commits

5 changed files with 48 additions and 33 deletions

View File

@ -15,6 +15,7 @@ enum Type {
}
const MAGNUS_SQ_EPSILON := 1e-3
const SURFACE_SNAP_DISTANCE := 2.0
## If enabled, ball ability cooldown is only reset at end of shot.
@export var once_per_shot_ability := false
@ -117,6 +118,22 @@ func get_damage() -> float:
return base_damage + linear_velocity.length_squared() * damage_force_scale
## Get the surface position immediately under the ball.
## This will typically be the surface the ball is laying on.
## If the ball is not on a surface, this will be the position of the ball itself.
func get_surface_snap_point() -> Vector3:
var params := PhysicsRayQueryParameters3D.create(
global_position,
global_position - get_reoriented_basis().y * SURFACE_SNAP_DISTANCE,
collision_mask,
[get_rid()]
)
var collisions := get_world_3d().direct_space_state.intersect_ray(params)
if collisions:
return collisions["position"] as Vector3
return global_position
func _magnus_force() -> Vector3:
return magnus_coefficient * radius * angular_velocity.cross(linear_velocity)
@ -133,13 +150,14 @@ func _integrate_forces(state: PhysicsDirectBodyState3D) -> void:
_surface_time_s = 0.0
# TODO something's fucky here... I think this gets called once after the ball sleeps
if state.get_contact_count():
var contacts := state.get_contact_count()
if contacts:
# Ball is in contact with a surface
# We want the contact normal which minimizes the angle to the up vector
var min_dot := -1.0
var min_dot := -2.0
var primary_body: Node
for i: int in range(state.get_contact_count()):
for i: int in range(contacts):
var norm := state.get_contact_local_normal(i)
var dot := norm.dot(Vector3.UP)
if dot > min_dot:
@ -175,8 +193,6 @@ func _physics_process(delta: float) -> void:
_shot_time_s += delta
_surface_time_s += delta
physics_material_override.bounce = terrain_physics.get_params(_surface_terrain).bounce
func enter_zone(zone: BallZone) -> void:
_zones.push_back(zone)
@ -225,6 +241,8 @@ func _on_collision(body: Node) -> void:
sfx.play_sfx(terrain)
effects.play_effect(terrain)
linear_velocity *= clampf(1 - terrain_physics.get_params(terrain).impact_damp, 0, 1)
func _fire_sleep_signal() -> void:
sleeping = true

View File

@ -5,63 +5,63 @@
[sub_resource type="Resource" id="Resource_casfi"]
script = ExtResource("1_45pis")
linear_damp = 1.15
linear_damp = 1.05
angular_damp = 3.0
bounce = 0.9
impact_damp = 0.05
[sub_resource type="Resource" id="Resource_3k63c"]
script = ExtResource("1_45pis")
linear_damp = 0.0
angular_damp = 0.0
bounce = 0.5
angular_damp = 0.01
impact_damp = 0.0
[sub_resource type="Resource" id="Resource_xf73q"]
script = ExtResource("1_45pis")
linear_damp = 4.4
linear_damp = 2.8
angular_damp = 4.0
bounce = 0.4
impact_damp = 0.3
[sub_resource type="Resource" id="Resource_nhn3l"]
script = ExtResource("1_45pis")
linear_damp = 0.86
angular_damp = 1.0
bounce = 0.9
impact_damp = 0.0
[sub_resource type="Resource" id="Resource_m3wjo"]
script = ExtResource("1_45pis")
linear_damp = 2.3
linear_damp = 1.25
angular_damp = 4.0
bounce = 0.4
impact_damp = 0.3
[sub_resource type="Resource" id="Resource_h4rld"]
script = ExtResource("1_45pis")
linear_damp = 1.62
angular_damp = 1.0
bounce = 0.9
impact_damp = 0.0
[sub_resource type="Resource" id="Resource_j6lib"]
script = ExtResource("1_45pis")
linear_damp = 4.7
linear_damp = 4.0
angular_damp = 2.0
bounce = 0.6
impact_damp = 0.15
[sub_resource type="Resource" id="Resource_7f7ql"]
script = ExtResource("1_45pis")
linear_damp = 7.6
angular_damp = 4.0
bounce = 0.3
linear_damp = 3.0
angular_damp = 8.0
impact_damp = 0.5
[sub_resource type="Resource" id="Resource_pusmf"]
script = ExtResource("1_45pis")
linear_damp = 12.0
angular_damp = 32.0
bounce = 0.0
linear_damp = 4.0
angular_damp = 4.0
impact_damp = 0.7
[sub_resource type="Resource" id="Resource_edkxb"]
script = ExtResource("1_45pis")
linear_damp = 1.55
linear_damp = 1.25
angular_damp = 1.3
bounce = 0.8
impact_damp = 0.15
[resource]
script = ExtResource("2_yuehx")

View File

@ -16,7 +16,7 @@
[ext_resource type="PackedScene" uid="uid://cm4bb3lg4mfd2" path="res://src/world/effects/splash/splash_effect.tscn" id="12_qlrvx"]
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_u134x"]
bounce = 0.4
bounce = 0.8
[sub_resource type="SphereMesh" id="SphereMesh_y0d13"]
material = ExtResource("3_rc7m1")

View File

@ -5,6 +5,6 @@ class_name TerrainParameters extends Resource
@export var linear_damp := 0.0
## Angular damping applied while in contact with the terrain surface.
@export var angular_damp := 0.0
## Physical bounciness of the terrain. Use this instead of the physics material override.
@export var bounce := 0.0
## Linear damping applied the frame the ball makes contact with the surface.
## This is applied in addition `linear_damp`.
@export var impact_damp := 0.0

View File

@ -393,7 +393,7 @@ func travel_to_ball() -> void:
return
game_ball.freeze = true
global_position = game_ball.global_position
global_position = game_ball.get_surface_snap_point()
# Re-orient to the ball's last contact normal if there is one.
# Normally this will just be Vector3.UP or something close to it.
@ -401,9 +401,6 @@ func travel_to_ball() -> void:
_target_rotation.y = 0
global_basis = game_ball.get_reoriented_basis()
# Adjust position downward to account for ball radius
global_position -= global_basis.y.normalized() * game_ball.radius
ball_point.snap()