change projectile type to RigidBody3D

This commit is contained in:
2025-09-17 01:17:22 +10:00
parent 7ba9a7625a
commit 55f9336c7a
6 changed files with 29 additions and 22 deletions

View File

@@ -35,7 +35,7 @@ var _queue_hit_stop: bool
func _ready() -> void:
Debugger.add_event("attacked")
attacked.connect(func() -> void: Debugger.event_emitted("attacked", []))
area_entered.connect(_on_area_entered)
body_entered.connect(_on_body_entered)
position.y = Projectile.HEIGHT
_set_collision_size(attack_radius)
@@ -152,7 +152,7 @@ func _hit_stop(time_scale: float, duration: float) -> void:
Engine.time_scale = 1
func _on_area_entered(node: Node3D) -> void:
func _on_body_entered(node: Node3D) -> void:
if _hit_window_timer <= 0:
return

View File

@@ -1,5 +1,5 @@
class_name Projectile
extends Area3D
extends RigidBody3D
const HEIGHT: float = 1
const MAX_STRETCH: float = 0.75
@@ -14,6 +14,7 @@ const MAX_STRETCH: float = 0.75
@export var _model_base: Node3D
@export var _model_mesh: MeshInstance3D
@export var _trail_particles: GPUParticles3D
@export var _collision_shape: CollisionShape3D
var _start_position: Vector3
var _velocity: Vector3
@@ -38,14 +39,17 @@ func _physics_process(delta: float) -> void:
queue_free()
_life_timer -= delta
global_position += _velocity * delta
look_at(global_position + _velocity, Vector3.UP, true)
linear_velocity = _velocity
if _velocity != Vector3.ZERO:
look_at(global_position + _velocity, Vector3.UP, true)
var speed := _velocity.length()
var speed_squash := clampf(speed / _speed_stretch_factor, 0, MAX_STRETCH)
_model_base.scale = Vector3(1 - speed_squash, 1 - speed_squash, 1 + speed_squash)
_trail_particles.amount = int(speed * _velocity_to_trail_rate)
_trail_particles.emitting = speed > 0
if speed > 0:
_trail_particles.amount = int(speed * _velocity_to_trail_rate)
func init(velocity: Vector3, start_position: Vector3, lifetime: float = 10) -> void:
@@ -60,10 +64,10 @@ func hit(velocity: Vector3) -> void:
)
get_tree().get_root().add_child(hit_particles)
hit_particles.init(global_position, velocity)
set_velocity(velocity)
_set_velocity(velocity)
func set_velocity(velocity: Vector3) -> void:
func _set_velocity(velocity: Vector3) -> void:
_velocity = velocity
_life_timer = _lifetime
@@ -74,15 +78,15 @@ func _destroy() -> void:
)
get_tree().get_root().add_child(destroy_particles)
destroy_particles.init(global_position)
set_deferred("monitorable", false)
set_deferred("monitoring", false)
set_deferred("freeze", true)
_collision_shape.set_deferred("disabled", true)
_velocity = Vector3.ZERO
linear_velocity = Vector3.ZERO
_model_base.visible = false
await get_tree().create_timer(5).timeout
await get_tree().create_timer(2).timeout
queue_free()
func _on_body_entered(node: Node3D) -> void:
if node is Player:
queue_free()