WIP: Spawn bullets on the server and sync them
This commit is contained in:
@ -160,8 +160,10 @@ func _rotate_camera(sens_mod: float = 1.0) -> void:
|
||||
first_view_camera_mount.rotation.x = clamp(first_view_camera_mount.rotation.x - look_dir.y * camera_sens * sens_mod, -1.5, 1.5)
|
||||
|
||||
@onready var health_indicator = $FirstPersonCameraMount/HUD/HealthIndicator
|
||||
@onready var fps_indicator = $FirstPersonCameraMount/HUD/FPS
|
||||
func _process(delta: float) -> void:
|
||||
health_indicator.text = str(health)
|
||||
fps_indicator.text = str(Engine.get_frames_per_second())
|
||||
if health == 0:
|
||||
queue_free()
|
||||
|
||||
@ -203,16 +205,21 @@ var bullet = load("res://scenes/weapon/bullet.tscn")
|
||||
@onready var bullet_starting_point: Node3D = $FirstPersonCameraMount/BulletStartingPoint
|
||||
@onready var aim_ray: RayCast3D = $FirstPersonCameraMount/BulletStartingPoint/AimRay
|
||||
# --find the gun node and exec shoot
|
||||
var cant_shoot: bool = false
|
||||
func _shoot():
|
||||
_send_shot_to_server.rpc_id(1, aim_ray.global_position)
|
||||
if aim_ray.is_colliding():
|
||||
var collider := aim_ray.get_collider()
|
||||
if collider != null and collider.is_in_group("target"):
|
||||
aim_ray.get_collider().take_damage()
|
||||
if collider != null and collider.is_in_group("body"):
|
||||
collider.hit()
|
||||
var root := get_tree().get_root()
|
||||
gun_with_hands.shoot()
|
||||
if not cant_shoot:
|
||||
_send_shot_to_server.rpc_id(1, aim_ray.global_position)
|
||||
if aim_ray.is_colliding():
|
||||
var collider := aim_ray.get_collider()
|
||||
if collider != null and collider.is_in_group("target"):
|
||||
aim_ray.get_collider().take_damage()
|
||||
if collider != null and collider.is_in_group("body"):
|
||||
collider.hit()
|
||||
var root := get_tree().get_root()
|
||||
gun_with_hands.shoot()
|
||||
cant_shoot = true
|
||||
await get_tree().create_timer(0.2).timeout
|
||||
cant_shoot = false
|
||||
|
||||
@rpc("any_peer", "call_local", "unreliable_ordered")
|
||||
func _send_shot_to_server(start_position):
|
||||
|
Reference in New Issue
Block a user