rework bullet speed a wee bit

This commit is contained in:
Haze Weathers 2026-01-03 10:17:41 -06:00
parent ddf3590c96
commit 08763960ca
5 changed files with 16 additions and 11 deletions

View file

@ -3,9 +3,6 @@ extends BulletBehavior
## Makes bullets move in [member Bullet.direction], potentially accelerating.
## Initial speed of the bullet when it is spawned.
@export_custom(0, "suffix:px/s") var initial_speed: float = 0.0
## Rate at which the bullet will speed up.
@export_custom(0, "suffix:px/s²") var acceleration: float = 0.0
@ -25,7 +22,6 @@ var _bullet_data: Dictionary[Bullet, Data] = {}
func _init_bullet(bullet: Bullet) -> void:
var data = Data.new()
data.speed = initial_speed
_bullet_data[bullet] = data
@ -37,15 +33,14 @@ func _process_bullet(bullet: Bullet, delta: float) -> void:
if not _bullet_data.has(bullet):
return
var data = _bullet_data[bullet]
data.speed += acceleration * delta
if not data.already_clamped and (data.speed <= min_speed or data.speed >= max_speed):
bullet.speed += acceleration * delta
if not data.already_clamped and (bullet.speed <= min_speed or bullet.speed >= max_speed):
data.already_clamped = true
if action_speed_clamped:
action_speed_clamped.perform(bullet)
data.speed = clampf(data.speed, min_speed, max_speed)
bullet.position += bullet.direction * data.speed * delta
bullet.speed = clampf(bullet.speed, min_speed, max_speed)
bullet.position += bullet.direction * bullet.speed * delta
class Data:
var speed: float
var already_clamped: bool = false