Implemented dynamic projectile spread.
This commit is contained in:
parent
029175ccde
commit
a9af69e7bb
5 changed files with 146 additions and 72 deletions
|
|
@ -1,11 +1,9 @@
|
|||
extends Area2D
|
||||
|
||||
|
||||
@onready var bullet: PackedScene = load("res://scenes/player_weapons/weapon_stock.tscn")
|
||||
@onready var shot_data: = load("res://resources/player_weapon_resources/weapon_shot_stock.tres")
|
||||
|
||||
|
||||
|
||||
# Time offset when this bullet was fired (relative to other bullets in the same shot)
|
||||
var time_offset: float = 0.5
|
||||
|
||||
|
|
@ -15,6 +13,9 @@ var fire_time: float = 0.0
|
|||
# Track if this bullet is currently active in the shot
|
||||
var is_active: bool = false
|
||||
|
||||
# Angle at which this bullet should fire (in degrees)
|
||||
var angle: float = 0.0
|
||||
|
||||
func _process(delta):
|
||||
var current_time = Time.get_ticks_msec() / 1000.0
|
||||
|
||||
|
|
@ -22,14 +23,20 @@ func _process(delta):
|
|||
if !is_active and current_time >= fire_time:
|
||||
activate()
|
||||
|
||||
# Calculate the movement vector based on speed, angle, and delta
|
||||
var angle_rad = deg_to_rad(angle)
|
||||
var move_x = cos(angle_rad) * shot_data.speed * delta
|
||||
var move_y = sin(angle_rad) * shot_data.speed * delta
|
||||
|
||||
# Move the bullet
|
||||
position.y -= shot_data.speed * delta
|
||||
position.x += move_x
|
||||
position.y += move_y
|
||||
|
||||
func activate():
|
||||
is_active = true
|
||||
visible = true
|
||||
|
||||
# # Emit signal for hit detection
|
||||
# Emit signal for hit detection (optional)
|
||||
# emit_signal("activate")
|
||||
|
||||
func _on_visible_on_screen_notifier_2d_screen_exited():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue