2024-02-22 06:22:22 +11:00
|
|
|
class_name ProjectileTower extends Tower
|
2023-11-15 15:19:40 +11:00
|
|
|
|
2024-02-22 06:22:22 +11:00
|
|
|
@export var projectile_scene: PackedScene
|
2023-11-15 15:19:40 +11:00
|
|
|
|
2024-02-22 06:22:22 +11:00
|
|
|
var force: float = 150.0
|
|
|
|
var projectile_id: int = 0
|
2023-11-15 15:19:40 +11:00
|
|
|
|
|
|
|
|
2024-02-22 06:22:22 +11:00
|
|
|
func shoot() -> void:
|
2023-11-15 15:19:40 +11:00
|
|
|
if is_multiplayer_authority():
|
|
|
|
networked_spawn_projectile.rpc(multiplayer.get_unique_id())
|
|
|
|
|
|
|
|
|
|
|
|
@rpc("reliable")
|
2024-02-22 06:22:22 +11:00
|
|
|
func networked_shoot() -> void:
|
2023-11-15 15:19:40 +11:00
|
|
|
super.networked_shoot()
|
|
|
|
shoot()
|
|
|
|
|
|
|
|
|
|
|
|
@rpc("reliable", "call_local")
|
2024-02-22 06:22:22 +11:00
|
|
|
func networked_spawn_projectile(peer_id: int) -> Projectile:
|
|
|
|
var projectile: Projectile = projectile_scene.instantiate() as Projectile
|
2023-11-19 18:47:52 +11:00
|
|
|
projectile.position = yaw_model.global_position
|
2023-11-15 15:19:40 +11:00
|
|
|
projectile.damage = damage
|
|
|
|
projectile.direction = -yaw_model.global_transform.basis.z
|
|
|
|
projectile.force = force
|
|
|
|
projectile.name = base_name + str(peer_id) + str(projectile_id)
|
|
|
|
get_tree().root.add_child(projectile)
|
|
|
|
projectile_id += 1
|
2023-11-17 20:49:38 +11:00
|
|
|
return projectile
|