generated from krampus/template-godot4
Compare commits
No commits in common. "115b31568fd1b98a7c57f7d84394b35a9ac66b68" and "cf185592d6fe9d1b3736542f5f747c75534716d7" have entirely different histories.
115b31568f
...
cf185592d6
|
@ -15,7 +15,6 @@ enum Type {
|
||||||
}
|
}
|
||||||
|
|
||||||
const MAGNUS_SQ_EPSILON := 1e-3
|
const MAGNUS_SQ_EPSILON := 1e-3
|
||||||
const SURFACE_SNAP_DISTANCE := 2.0
|
|
||||||
|
|
||||||
## If enabled, ball ability cooldown is only reset at end of shot.
|
## If enabled, ball ability cooldown is only reset at end of shot.
|
||||||
@export var once_per_shot_ability := false
|
@export var once_per_shot_ability := false
|
||||||
|
@ -118,22 +117,6 @@ func get_damage() -> float:
|
||||||
return base_damage + linear_velocity.length_squared() * damage_force_scale
|
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:
|
func _magnus_force() -> Vector3:
|
||||||
return magnus_coefficient * radius * angular_velocity.cross(linear_velocity)
|
return magnus_coefficient * radius * angular_velocity.cross(linear_velocity)
|
||||||
|
|
||||||
|
@ -150,14 +133,13 @@ func _integrate_forces(state: PhysicsDirectBodyState3D) -> void:
|
||||||
_surface_time_s = 0.0
|
_surface_time_s = 0.0
|
||||||
# TODO something's fucky here... I think this gets called once after the ball sleeps
|
# TODO something's fucky here... I think this gets called once after the ball sleeps
|
||||||
|
|
||||||
var contacts := state.get_contact_count()
|
if state.get_contact_count():
|
||||||
if contacts:
|
|
||||||
# Ball is in contact with a surface
|
# Ball is in contact with a surface
|
||||||
|
|
||||||
# We want the contact normal which minimizes the angle to the up vector
|
# We want the contact normal which minimizes the angle to the up vector
|
||||||
var min_dot := -2.0
|
var min_dot := -1.0
|
||||||
var primary_body: Node
|
var primary_body: Node
|
||||||
for i: int in range(contacts):
|
for i: int in range(state.get_contact_count()):
|
||||||
var norm := state.get_contact_local_normal(i)
|
var norm := state.get_contact_local_normal(i)
|
||||||
var dot := norm.dot(Vector3.UP)
|
var dot := norm.dot(Vector3.UP)
|
||||||
if dot > min_dot:
|
if dot > min_dot:
|
||||||
|
@ -193,6 +175,8 @@ func _physics_process(delta: float) -> void:
|
||||||
_shot_time_s += delta
|
_shot_time_s += delta
|
||||||
_surface_time_s += delta
|
_surface_time_s += delta
|
||||||
|
|
||||||
|
physics_material_override.bounce = terrain_physics.get_params(_surface_terrain).bounce
|
||||||
|
|
||||||
|
|
||||||
func enter_zone(zone: BallZone) -> void:
|
func enter_zone(zone: BallZone) -> void:
|
||||||
_zones.push_back(zone)
|
_zones.push_back(zone)
|
||||||
|
@ -241,8 +225,6 @@ func _on_collision(body: Node) -> void:
|
||||||
sfx.play_sfx(terrain)
|
sfx.play_sfx(terrain)
|
||||||
effects.play_effect(terrain)
|
effects.play_effect(terrain)
|
||||||
|
|
||||||
linear_velocity *= clampf(1 - terrain_physics.get_params(terrain).impact_damp, 0, 1)
|
|
||||||
|
|
||||||
|
|
||||||
func _fire_sleep_signal() -> void:
|
func _fire_sleep_signal() -> void:
|
||||||
sleeping = true
|
sleeping = true
|
||||||
|
|
|
@ -5,63 +5,63 @@
|
||||||
|
|
||||||
[sub_resource type="Resource" id="Resource_casfi"]
|
[sub_resource type="Resource" id="Resource_casfi"]
|
||||||
script = ExtResource("1_45pis")
|
script = ExtResource("1_45pis")
|
||||||
linear_damp = 1.05
|
linear_damp = 1.15
|
||||||
angular_damp = 3.0
|
angular_damp = 3.0
|
||||||
impact_damp = 0.05
|
bounce = 0.9
|
||||||
|
|
||||||
[sub_resource type="Resource" id="Resource_3k63c"]
|
[sub_resource type="Resource" id="Resource_3k63c"]
|
||||||
script = ExtResource("1_45pis")
|
script = ExtResource("1_45pis")
|
||||||
linear_damp = 0.0
|
linear_damp = 0.0
|
||||||
angular_damp = 0.01
|
angular_damp = 0.0
|
||||||
impact_damp = 0.0
|
bounce = 0.5
|
||||||
|
|
||||||
[sub_resource type="Resource" id="Resource_xf73q"]
|
[sub_resource type="Resource" id="Resource_xf73q"]
|
||||||
script = ExtResource("1_45pis")
|
script = ExtResource("1_45pis")
|
||||||
linear_damp = 2.8
|
linear_damp = 4.4
|
||||||
angular_damp = 4.0
|
angular_damp = 4.0
|
||||||
impact_damp = 0.3
|
bounce = 0.4
|
||||||
|
|
||||||
[sub_resource type="Resource" id="Resource_nhn3l"]
|
[sub_resource type="Resource" id="Resource_nhn3l"]
|
||||||
script = ExtResource("1_45pis")
|
script = ExtResource("1_45pis")
|
||||||
linear_damp = 0.86
|
linear_damp = 0.86
|
||||||
angular_damp = 1.0
|
angular_damp = 1.0
|
||||||
impact_damp = 0.0
|
bounce = 0.9
|
||||||
|
|
||||||
[sub_resource type="Resource" id="Resource_m3wjo"]
|
[sub_resource type="Resource" id="Resource_m3wjo"]
|
||||||
script = ExtResource("1_45pis")
|
script = ExtResource("1_45pis")
|
||||||
linear_damp = 1.25
|
linear_damp = 2.3
|
||||||
angular_damp = 4.0
|
angular_damp = 4.0
|
||||||
impact_damp = 0.3
|
bounce = 0.4
|
||||||
|
|
||||||
[sub_resource type="Resource" id="Resource_h4rld"]
|
[sub_resource type="Resource" id="Resource_h4rld"]
|
||||||
script = ExtResource("1_45pis")
|
script = ExtResource("1_45pis")
|
||||||
linear_damp = 1.62
|
linear_damp = 1.62
|
||||||
angular_damp = 1.0
|
angular_damp = 1.0
|
||||||
impact_damp = 0.0
|
bounce = 0.9
|
||||||
|
|
||||||
[sub_resource type="Resource" id="Resource_j6lib"]
|
[sub_resource type="Resource" id="Resource_j6lib"]
|
||||||
script = ExtResource("1_45pis")
|
script = ExtResource("1_45pis")
|
||||||
linear_damp = 4.0
|
linear_damp = 4.7
|
||||||
angular_damp = 2.0
|
angular_damp = 2.0
|
||||||
impact_damp = 0.15
|
bounce = 0.6
|
||||||
|
|
||||||
[sub_resource type="Resource" id="Resource_7f7ql"]
|
[sub_resource type="Resource" id="Resource_7f7ql"]
|
||||||
script = ExtResource("1_45pis")
|
script = ExtResource("1_45pis")
|
||||||
linear_damp = 3.0
|
linear_damp = 7.6
|
||||||
angular_damp = 8.0
|
angular_damp = 4.0
|
||||||
impact_damp = 0.5
|
bounce = 0.3
|
||||||
|
|
||||||
[sub_resource type="Resource" id="Resource_pusmf"]
|
[sub_resource type="Resource" id="Resource_pusmf"]
|
||||||
script = ExtResource("1_45pis")
|
script = ExtResource("1_45pis")
|
||||||
linear_damp = 4.0
|
linear_damp = 12.0
|
||||||
angular_damp = 4.0
|
angular_damp = 32.0
|
||||||
impact_damp = 0.7
|
bounce = 0.0
|
||||||
|
|
||||||
[sub_resource type="Resource" id="Resource_edkxb"]
|
[sub_resource type="Resource" id="Resource_edkxb"]
|
||||||
script = ExtResource("1_45pis")
|
script = ExtResource("1_45pis")
|
||||||
linear_damp = 1.25
|
linear_damp = 1.55
|
||||||
angular_damp = 1.3
|
angular_damp = 1.3
|
||||||
impact_damp = 0.15
|
bounce = 0.8
|
||||||
|
|
||||||
[resource]
|
[resource]
|
||||||
script = ExtResource("2_yuehx")
|
script = ExtResource("2_yuehx")
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
[ext_resource type="PackedScene" uid="uid://cm4bb3lg4mfd2" path="res://src/world/effects/splash/splash_effect.tscn" id="12_qlrvx"]
|
[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"]
|
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_u134x"]
|
||||||
bounce = 0.8
|
bounce = 0.4
|
||||||
|
|
||||||
[sub_resource type="SphereMesh" id="SphereMesh_y0d13"]
|
[sub_resource type="SphereMesh" id="SphereMesh_y0d13"]
|
||||||
material = ExtResource("3_rc7m1")
|
material = ExtResource("3_rc7m1")
|
||||||
|
|
|
@ -5,6 +5,6 @@ class_name TerrainParameters extends Resource
|
||||||
@export var linear_damp := 0.0
|
@export var linear_damp := 0.0
|
||||||
## Angular damping applied while in contact with the terrain surface.
|
## Angular damping applied while in contact with the terrain surface.
|
||||||
@export var angular_damp := 0.0
|
@export var angular_damp := 0.0
|
||||||
## Linear damping applied the frame the ball makes contact with the surface.
|
|
||||||
## This is applied in addition `linear_damp`.
|
## Physical bounciness of the terrain. Use this instead of the physics material override.
|
||||||
@export var impact_damp := 0.0
|
@export var bounce := 0.0
|
||||||
|
|
|
@ -393,7 +393,7 @@ func travel_to_ball() -> void:
|
||||||
return
|
return
|
||||||
|
|
||||||
game_ball.freeze = true
|
game_ball.freeze = true
|
||||||
global_position = game_ball.get_surface_snap_point()
|
global_position = game_ball.global_position
|
||||||
|
|
||||||
# Re-orient to the ball's last contact normal if there is one.
|
# 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.
|
# Normally this will just be Vector3.UP or something close to it.
|
||||||
|
@ -401,6 +401,9 @@ func travel_to_ball() -> void:
|
||||||
_target_rotation.y = 0
|
_target_rotation.y = 0
|
||||||
global_basis = game_ball.get_reoriented_basis()
|
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()
|
ball_point.snap()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue