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

@ -20,7 +20,6 @@ metadata/_custom_type_script = "uid://0ognvvq2ncd7"
[sub_resource type="Resource" id="Resource_t1bs8"] [sub_resource type="Resource" id="Resource_t1bs8"]
script = ExtResource("4_t1bs8") script = ExtResource("4_t1bs8")
initial_speed = 120.0
metadata/_custom_type_script = "uid://dntp60my5f65m" metadata/_custom_type_script = "uid://dntp60my5f65m"
[sub_resource type="Resource" id="Resource_1xo0o"] [sub_resource type="Resource" id="Resource_1xo0o"]
@ -32,7 +31,8 @@ metadata/_custom_type_script = "uid://0ognvvq2ncd7"
[sub_resource type="Resource" id="Resource_4oowd"] [sub_resource type="Resource" id="Resource_4oowd"]
script = ExtResource("6_uu3sg") script = ExtResource("6_uu3sg")
radius = 32.0 bullet_count = 1
bullet_speed = 120.0
metadata/_custom_type_script = "uid://dtuc6qerbfset" metadata/_custom_type_script = "uid://dtuc6qerbfset"
[sub_resource type="Resource" id="Resource_sle1e"] [sub_resource type="Resource" id="Resource_sle1e"]
@ -44,6 +44,7 @@ property_min_values = Dictionary[StringName, float]({
property_max_values = Dictionary[StringName, float]({ property_max_values = Dictionary[StringName, float]({
&"direction_rotation": 3.142 &"direction_rotation": 3.142
}) })
iterations = 50
metadata/_custom_type_script = "uid://ckedfcjjnv7dq" metadata/_custom_type_script = "uid://ckedfcjjnv7dq"
[sub_resource type="Resource" id="Resource_hxqcc"] [sub_resource type="Resource" id="Resource_hxqcc"]

View file

@ -38,6 +38,9 @@ static var _hitbox_shapes: Dictionary[Vector2i, RectangleShape2D] = {}
_hitbox_shapes[hitbox_size] = new_shape _hitbox_shapes[hitbox_size] = new_shape
_hitbox.shape = _hitbox_shapes[hitbox_size] _hitbox.shape = _hitbox_shapes[hitbox_size]
## The speed at which the bullet should travel.
@export var speed: float
## The direction that the bullet is travelling. ## The direction that the bullet is travelling.
@export_custom(0, "direction") var direction: Vector2 = Vector2.RIGHT @export_custom(0, "direction") var direction: Vector2 = Vector2.RIGHT

View file

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

View file

@ -5,6 +5,8 @@ extends BulletSpawnPattern
## Number of bullets to spawn along the line. ## Number of bullets to spawn along the line.
@export var bullet_count: int @export var bullet_count: int
## The speed that bullets will start with.
@export var bullet_speed: float
## Distance between the first and last bullet in the line. ## Distance between the first and last bullet in the line.
@export var line_width: float @export var line_width: float
## The direction that spawned bullets will travel, orthogonal to the line of bullets. ## The direction that spawned bullets will travel, orthogonal to the line of bullets.
@ -14,6 +16,7 @@ extends BulletSpawnPattern
func _spawn_bullets(bullet_set: BulletSet, preset: BulletPreset) -> void: func _spawn_bullets(bullet_set: BulletSet, preset: BulletPreset) -> void:
for i in bullet_count: for i in bullet_count:
var bullet = Bullet.create(preset, line_normal.rotated(bullet_set.spawn_rotation)) var bullet = Bullet.create(preset, line_normal.rotated(bullet_set.spawn_rotation))
bullet.speed = bullet_speed
var line = line_normal.orthogonal().rotated(bullet_set.spawn_rotation) var line = line_normal.orthogonal().rotated(bullet_set.spawn_rotation)
var weight = float(i) / float(bullet_count - 1) var weight = float(i) / float(bullet_count - 1)

View file

@ -5,6 +5,8 @@ extends BulletSpawnPattern
## The number of bullets to spawn along the circle. ## The number of bullets to spawn along the circle.
@export var bullet_count: int = 3 @export var bullet_count: int = 3
## The speed that bullets will start with.
@export var bullet_speed: float
## Radius of the circle that bullets spawn along the edge of. ## Radius of the circle that bullets spawn along the edge of.
@export var radius: float @export var radius: float
## Rotation of the entire ring pattern. ## Rotation of the entire ring pattern.
@ -17,5 +19,6 @@ func _spawn_bullets(bullet_set: BulletSet, preset: BulletPreset) -> void:
for i in bullet_count: for i in bullet_count:
var angle = (float(i) / float(bullet_count)) * TAU + angle_offset + bullet_set.spawn_rotation var angle = (float(i) / float(bullet_count)) * TAU + angle_offset + bullet_set.spawn_rotation
var bullet = Bullet.create(preset, Vector2.from_angle(angle + direction_rotation)) var bullet = Bullet.create(preset, Vector2.from_angle(angle + direction_rotation))
bullet.speed = bullet_speed
bullet.position = bullet_set.spawn_offset + Vector2.from_angle(angle) * radius bullet.position = bullet_set.spawn_offset + Vector2.from_angle(angle) * radius
bullet_set.add_bullet(bullet) bullet_set.add_bullet(bullet)