feat: adding tracers to hitscan weapons
This commit is contained in:
@@ -130,6 +130,7 @@ func _shoot_hitscan() -> void:
|
||||
|
||||
var hits_remaining = penetration_count + 1
|
||||
var current_damage_mult = 1.0
|
||||
var final_target = target
|
||||
|
||||
while hits_remaining > 0:
|
||||
var result = space_state.intersect_ray(query)
|
||||
@@ -156,3 +157,35 @@ func _shoot_hitscan() -> void:
|
||||
|
||||
hits_remaining -= 1
|
||||
current_damage_mult *= penetration_damage_penalty
|
||||
final_target = result.position
|
||||
|
||||
# Spawn cosmetic tracer
|
||||
var tracer = Node3D.new()
|
||||
tracer.set_script(load("res://weapons/hitscan_tracer.gd"))
|
||||
|
||||
var t_mesh_inst = MeshInstance3D.new()
|
||||
var t_mesh = CapsuleMesh.new()
|
||||
t_mesh.radius = 0.02
|
||||
t_mesh.height = 1.0
|
||||
var t_mat = StandardMaterial3D.new()
|
||||
t_mat.albedo_color = Color(1.0, 0.8, 0.2) # Yellow-orange tracer
|
||||
t_mat.emission_enabled = true
|
||||
t_mat.emission = Color(2.0, 1.5, 0.5)
|
||||
t_mesh.material = t_mat
|
||||
|
||||
t_mesh_inst.mesh = t_mesh
|
||||
t_mesh_inst.rotation.x = deg_to_rad(90) # Orient capsule along Z axis
|
||||
t_mesh_inst.position = Vector3(0, 0, -0.5) # Shift it half a meter forward so the tail is at the origin
|
||||
tracer.add_child(t_mesh_inst)
|
||||
|
||||
tracer.target_position = final_target
|
||||
var visual_origin = muzzle_flash.global_position if muzzle_flash else global_position # Spawn from the barrel tip
|
||||
|
||||
if visual_origin.distance_squared_to(final_target) > 0.1:
|
||||
get_tree().current_scene.add_child(tracer)
|
||||
tracer.global_position = visual_origin
|
||||
|
||||
var up_vec = Vector3.UP
|
||||
if abs((final_target - visual_origin).normalized().dot(up_vec)) > 0.99:
|
||||
up_vec = Vector3.RIGHT
|
||||
tracer.look_at(final_target, up_vec)
|
||||
|
||||
Reference in New Issue
Block a user