generated from krampus/template-godot4
Damage scales with speed & type
This commit is contained in:
parent
42d1a9a77c
commit
15cd409e04
|
@ -44,6 +44,9 @@ const IRON_DAMPING := 9999.0
|
||||||
## Base damage inflicted on impact with a player
|
## Base damage inflicted on impact with a player
|
||||||
@export var base_damage := 15.0
|
@export var base_damage := 15.0
|
||||||
|
|
||||||
|
## Scaling factor for additional force-based damage
|
||||||
|
@export var damage_force_scale := 0.01
|
||||||
|
|
||||||
var _last_contact_normal: Vector3 = Vector3.UP
|
var _last_contact_normal: Vector3 = Vector3.UP
|
||||||
var _position_on_last_wake: Vector3
|
var _position_on_last_wake: Vector3
|
||||||
var _awake := false
|
var _awake := false
|
||||||
|
@ -64,6 +67,11 @@ func enter_water() -> void:
|
||||||
entered_water.emit()
|
entered_water.emit()
|
||||||
|
|
||||||
|
|
||||||
|
func get_damage() -> float:
|
||||||
|
print("velocity: ", linear_velocity.length())
|
||||||
|
return base_damage + linear_velocity.length_squared() * damage_force_scale
|
||||||
|
|
||||||
|
|
||||||
func _total_terrain_angular_damping() -> float:
|
func _total_terrain_angular_damping() -> float:
|
||||||
return _zones.reduce(
|
return _zones.reduce(
|
||||||
func(a: float, b: BallZone) -> float: return a + b.terrain_angular_damping, 0.0
|
func(a: float, b: BallZone) -> float: return a + b.terrain_angular_damping, 0.0
|
||||||
|
|
|
@ -49,6 +49,7 @@ size = Vector2(0.4, 0.4)
|
||||||
|
|
||||||
[node name="PlasmaBall" instance=ExtResource("1_yh4fp")]
|
[node name="PlasmaBall" instance=ExtResource("1_yh4fp")]
|
||||||
script = ExtResource("2_pdts3")
|
script = ExtResource("2_pdts3")
|
||||||
|
base_damage = 30.0
|
||||||
|
|
||||||
[node name="PlasmaFireEffect" type="GPUParticles3D" parent="BallMesh" index="0"]
|
[node name="PlasmaFireEffect" type="GPUParticles3D" parent="BallMesh" index="0"]
|
||||||
amount = 20
|
amount = 20
|
||||||
|
|
|
@ -583,9 +583,10 @@ func _on_ball_return_timer_timeout() -> void:
|
||||||
|
|
||||||
func _on_hitbox_ball_collision(ball: GameBall) -> void:
|
func _on_hitbox_ball_collision(ball: GameBall) -> void:
|
||||||
# TODO play animation
|
# TODO play animation
|
||||||
player.life -= ball.base_damage
|
var damage := ball.get_damage()
|
||||||
|
player.life -= damage
|
||||||
game.viewport.hit_lag_big()
|
game.viewport.hit_lag_big()
|
||||||
game.viewport.screen_shake(ball.base_damage, 0.4)
|
game.viewport.screen_shake(damage, 0.4)
|
||||||
explosion_animation.play("explode")
|
explosion_animation.play("explode")
|
||||||
# TODO kinematic collisions
|
# TODO kinematic collisions
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue