Nearl implemented: bullet rotation isn't working correctly.

This commit is contained in:
Henry Faber 2026-06-16 13:56:47 +01:00
parent a9af69e7bb
commit f427bb0c8d
11 changed files with 161 additions and 9 deletions

View file

@ -1,8 +1,6 @@
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")
@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
@ -16,6 +14,9 @@ var is_active: bool = false
# Angle at which this bullet should fire (in degrees)
var angle: float = 0.0
# Whether to rotate bullet to face its movement direction
var rotate_to_velocity: bool = true
func _process(delta):
var current_time = Time.get_ticks_msec() / 1000.0
@ -32,13 +33,19 @@ func _process(delta):
position.x += move_x
position.y += move_y
# Rotate to face movement direction - ensure proper rotation calculation
if rotate_to_velocity:
var velocity = Vector2(cos(angle_rad) * shot_data.speed, sin(angle_rad) * shot_data.speed)
rotation = velocity.angle()
# Debug output - this will show you what's really happening
print("Bullet angle: ", angle, "Velocity angle:", velocity.angle(), "Rotation set to:", rotation)
func activate():
is_active = true
visible = true
# Emit signal for hit detection (optional)
# emit_signal("activate")
func _on_visible_on_screen_notifier_2d_screen_exited():
queue_free()

View file

@ -0,0 +1,54 @@
extends Area2D
@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
# When this bullet should fire (absolute time)
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
# Whether to rotate bullet to face its movement direction
var rotate_to_velocity: bool = true
func _process(delta):
var current_time = Time.get_ticks_msec() / 1000.0
# Fire if it's time and bullet isn't already active
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.x += move_x
position.y += move_y
# Rotate to face movement direction - ensure proper rotation calculation
if rotate_to_velocity:
var velocity = Vector2(cos(angle_rad) * shot_data.speed, sin(angle_rad) * shot_data.speed)
rotation = velocity.angle()
# Debug output - this will show you what's really happening
print("Bullet angle: ", angle, "Velocity angle:", velocity.angle(), "Rotation set to:", rotation)
func activate():
is_active = true
visible = true
func _on_visible_on_screen_notifier_2d_screen_exited():
queue_free()
# Set fire_time for the next shot (staggered firing)
var current_time = Time.get_ticks_msec() / 1000.0
fire_time = current_time + shot_data.stagger_offset

View file

@ -0,0 +1 @@
uid://7wuopfptd3qe

View file

@ -0,0 +1,54 @@
extends Area2D
@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
# When this bullet should fire (absolute time)
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
# Whether to rotate bullet to face its movement direction
var rotate_to_velocity: bool = true
func _process(delta):
var current_time = Time.get_ticks_msec() / 1000.0
# Fire if it's time and bullet isn't already active
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.x += move_x
position.y += move_y
# Rotate to face movement direction - ensure proper rotation calculation
if rotate_to_velocity:
var velocity = Vector2(cos(angle_rad) * shot_data.speed, sin(angle_rad) * shot_data.speed)
rotation = velocity.angle()
# Debug output - this will show you what's really happening
print("Bullet angle: ", angle, "Velocity angle:", velocity.angle(), "Rotation set to:", rotation)
func activate():
is_active = true
visible = true
func _on_visible_on_screen_notifier_2d_screen_exited():
queue_free()
# Set fire_time for the next shot (staggered firing)
var current_time = Time.get_ticks_msec() / 1000.0
fire_time = current_time + shot_data.stagger_offset

View file

@ -0,0 +1 @@
uid://c1u6yrjkp26i5