generated from krampus/template-godot4
Adjusted shot curve calculation
This commit is contained in:
parent
7c3a3e58d7
commit
fb19b1a1ad
|
@ -36,7 +36,10 @@ const BIG_POWER_THRESHOLD := 0.7
|
|||
const WATER_DAMAGE := 10.0
|
||||
|
||||
## Angle of influence that shot curve has, in radians
|
||||
const CURVE_INFLUENCE := PI / 8
|
||||
const CURVE_INFLUENCE := PI / 16
|
||||
|
||||
## Impulse offset multiplier due to curve, in meters
|
||||
const CURVE_FACTOR := 0.002
|
||||
|
||||
## Maximum absolute curve for the "nice shot" animation to play
|
||||
const NICE_THRESHOLD := 0.2
|
||||
|
@ -238,12 +241,12 @@ func finish_downswing() -> void:
|
|||
|
||||
|
||||
func get_shot_impulse(meter_pct: float) -> Vector3:
|
||||
return (
|
||||
-direction.global_basis.rotated(direction.global_basis.x, club.angle).z
|
||||
* club.power
|
||||
* base_power
|
||||
* meter_pct
|
||||
)
|
||||
# Basic direction of the shot
|
||||
var shot_vec := -direction.global_basis.rotated(direction.global_basis.x, club.angle).z
|
||||
# Curve rotates shot direction around the Y-axis
|
||||
var curved_shot := shot_vec.rotated(Vector3.UP, shot_curve * CURVE_INFLUENCE * shot_power)
|
||||
# Various factors attenuate shot power
|
||||
return curved_shot * club.power * base_power * meter_pct
|
||||
|
||||
|
||||
func take_shot() -> void:
|
||||
|
@ -262,13 +265,11 @@ func take_shot() -> void:
|
|||
print_debug("Shot impulse: ", impulse, "; ", impulse.length(), " N*s")
|
||||
|
||||
# Curve the curve
|
||||
var curve := direction.global_basis.x.normalized() * shot_curve
|
||||
var curve := direction.global_basis.x.normalized() * shot_curve * absf(shot_curve)
|
||||
|
||||
# Position where the ball is hit (imparts spin)
|
||||
var offset := curve * 0.001
|
||||
var offset := -curve * CURVE_FACTOR
|
||||
print_debug("Shot offset: ", offset, "; ", offset.length(), " m")
|
||||
# Rotate impulse
|
||||
impulse = impulse.rotated(Vector3.UP, -shot_curve * CURVE_INFLUENCE * shot_power)
|
||||
|
||||
if game_ball:
|
||||
game_ball.iron_ball = club_type == Club.Type.IRON
|
||||
|
|
Loading…
Reference in New Issue