game: add bullet and impacts

This commit is contained in:
2025-08-15 04:08:08 +02:00
parent 4ccc962e34
commit 3d54d70e44
19 changed files with 411 additions and 10 deletions

29
game/bullet.gd Normal file
View File

@@ -0,0 +1,29 @@
extends Node3D
const SPEED = 80.0
@onready var raycast = $bullet/RayCast3D
@onready var bullet_decal = preload("res://bullet_decal.tscn")
func _ready() -> void:
pass
func _process(delta: float) -> void:
var next_pos = position + transform.basis * Vector3(0,0,-SPEED) * delta
raycast.visible = true
raycast.target_position = raycast.position + raycast.transform.basis * Vector3(0,0,SPEED) * delta * 1.5
position = next_pos
var collider = raycast.get_collider()
var col_point = raycast.get_collision_point()
if col_point and collider:
var b = bullet_decal.instantiate()
raycast.get_collider().add_child(b)
b.global_transform.origin = col_point
b.look_at(col_point + raycast.get_collision_normal(), Vector3.UP)
b.particles.emitting = true
b.smoke.emitting = true
queue_free()
func _on_timer_timeout() -> void:
queue_free()