game: add bullet and impacts
This commit is contained in:
29
game/bullet.gd
Normal file
29
game/bullet.gd
Normal 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()
|
Reference in New Issue
Block a user