27 lines
782 B
GDScript3
27 lines
782 B
GDScript3
|
class_name Bullet
|
||
|
extends CharacterBody3D
|
||
|
|
||
|
const SPEED: int = 20
|
||
|
|
||
|
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()
|