Want to contribute? Fork me on Codeberg.org!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
719 B

extends Node2D
@export var bullet: PackedScene
@export var spread = 10.0
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
if Input.is_action_just_pressed("fire"):
fire.rpc()
@rpc("any_peer", "call_local")
func fire():
var authority = get_parent().get_node("MultiplayerSynchronizer").get_multiplayer_authority()
if authority != get_multiplayer_authority():
return;
var new_bullet = bullet.instantiate()
new_bullet.position = global_position
new_bullet.velocity = Vector2.from_angle(rotation + deg_to_rad(randf_range(-spread / 2, spread / 2))) * new_bullet.speed;
get_tree().root.add_child(new_bullet)
get_parent().x_velocity_offset = -600 * cos(rotation)