Updates
This commit is contained in:
parent
8d5714c215
commit
ffba3fce8c
12 changed files with 202 additions and 5 deletions
20
gun.gd
Normal file
20
gun.gd
Normal file
|
@ -0,0 +1,20 @@
|
|||
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)
|
Loading…
Add table
Add a link
Reference in a new issue