29 lines
878 B
GDScript
29 lines
878 B
GDScript
## SPDX-License-Identifier: GPL-3.0-or-later
|
|
## Copyright (c) 2024 interstellardevelopment.org
|
|
|
|
class_name Bullet
|
|
extends CharacterBody3D
|
|
|
|
const SPEED: int = 40
|
|
|
|
func _ready() -> void:
|
|
if ($Timer as Timer).timeout.connect(_on_timeout):
|
|
pass
|
|
|
|
func _on_timeout() -> void:
|
|
queue_free()
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
var direction: Vector3 = (transform.basis * Vector3(0, 0, -1)).normalized()
|
|
if direction:
|
|
velocity.x = direction.x * SPEED
|
|
velocity.z = direction.z * SPEED
|
|
|
|
var collision: KinematicCollision3D = move_and_collide(velocity * delta)
|
|
|
|
if collision != null:
|
|
if collision.get_collider() is NPC and (collision.get_collider() as NPC).carried_object != null and Networking.isManager:
|
|
Networking.set_down_sync_call((collision.get_collider() as NPC), (collision.get_collider() as NPC).carried_object)
|
|
queue_free()
|
|
else:
|
|
queue_free()
|