Added multiplayer synchronization for bullet impact effects

remotes/1705382094874458415/tmp_refs/heads/godot4-port
Jan 2020-09-18 22:39:22 +02:00
parent 9d28597f29
commit c2fed43e86
3 changed files with 22 additions and 15 deletions

View File

@ -1,7 +1,8 @@
[gd_scene load_steps=13 format=2]
[gd_scene load_steps=14 format=2]
[ext_resource path="res://LevelComponents/Killfloor.tscn" type="PackedScene" id=1]
[ext_resource path="res://LevelComponents/SpawnPoint.tscn" type="PackedScene" id=2]
[ext_resource path="res://LevelComponents/LevelGeometry.gd" type="Script" id=3]
[sub_resource type="BoxShape" id=1]
@ -22,7 +23,7 @@ uniform_name = "ScalarUniform"
[sub_resource type="VisualShader" id=6]
code = "shader_type spatial;
render_mode world_vertex_coords;
render_mode specular_schlick_ggx, world_vertex_coords;
uniform sampler2D BaseTexture : hint_albedo;
uniform float ScalarUniform;
@ -146,6 +147,7 @@ material/0 = null
[node name="CSGCombiner" type="CSGCombiner" parent="."]
material_override = SubResource( 10 )
use_collision = true
script = ExtResource( 3 )
[node name="CSGBox" type="CSGBox" parent="CSGCombiner"]
width = 14.0
@ -163,10 +165,10 @@ height = 14.0
sides = 16
[node name="CSGCylinder2" type="CSGCylinder" parent="CSGCombiner"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -4, 8, 4 )
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -4, 10.5677, 4 )
operation = 2
radius = 2.0
height = 13.8871
height = 14.1775
sides = 16
[node name="CSGBox2" type="CSGBox" parent="CSGCombiner"]

View File

@ -0,0 +1,8 @@
extends CSGCombiner
var bulletHitEffect = preload("res://Assets/Effects/BulletHit.tscn")
remotesync func on_hit(damage, position):
var effect = bulletHitEffect.instance()
effect.global_transform.origin = position
get_tree().root.call_deferred("add_child", effect)

View File

@ -138,12 +138,17 @@ func _physics_process(delta):
rset("translation", translation)
master func on_hit():
master func on_hit(damage, location):
health -= 30
rpc("blood_splatter", location)
if health <= 0:
rpc("kill")
remote func blood_splatter(location):
pass
master func kill():
health = 0
spawn()
@ -153,7 +158,6 @@ func spawn():
game.get_spawn_point().spawn(self)
func shoot():
var gun = find_node("Weapon")
gun.shoot()
@ -161,8 +165,6 @@ func shoot():
var space_state = get_world().direct_space_state
var crosshair_pos = get_viewport().size / 2
print(OS.get_real_window_size()/2)
var from = $Camera.project_ray_origin(crosshair_pos)
var to = from + $Camera.project_ray_normal(crosshair_pos) * 1000
@ -170,14 +172,9 @@ func shoot():
if "collider" in result:
var hit = result.collider
print(hit)
if hit.has_method("on_hit"):
hit.rpc("on_hit")
else:
var effect = bulletHitEffect.instance()
effect.global_transform.origin = result.position
get_tree().root.call_deferred("add_child", effect)
hit.rpc("on_hit", 30, result.position)
func _input(event):
if str(get_tree().get_network_unique_id()) != name: