generated from krampus/template-godot4
Shot setup snaps to ground using raycast
This commit is contained in:
parent
2b4495bbc9
commit
115b31568f
|
@ -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)
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ impact_damp = 0.05
|
|||
[sub_resource type="Resource" id="Resource_3k63c"]
|
||||
script = ExtResource("1_45pis")
|
||||
linear_damp = 0.0
|
||||
angular_damp = 0.0
|
||||
angular_damp = 0.01
|
||||
impact_damp = 0.0
|
||||
|
||||
[sub_resource type="Resource" id="Resource_xf73q"]
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue