Added multiplayer synchronization for bullet impact effects
parent
9d28597f29
commit
c2fed43e86
10
Level.tscn
10
Level.tscn
|
@ -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/Killfloor.tscn" type="PackedScene" id=1]
|
||||||
[ext_resource path="res://LevelComponents/SpawnPoint.tscn" type="PackedScene" id=2]
|
[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]
|
[sub_resource type="BoxShape" id=1]
|
||||||
|
|
||||||
|
@ -22,7 +23,7 @@ uniform_name = "ScalarUniform"
|
||||||
|
|
||||||
[sub_resource type="VisualShader" id=6]
|
[sub_resource type="VisualShader" id=6]
|
||||||
code = "shader_type spatial;
|
code = "shader_type spatial;
|
||||||
render_mode world_vertex_coords;
|
render_mode specular_schlick_ggx, world_vertex_coords;
|
||||||
|
|
||||||
uniform sampler2D BaseTexture : hint_albedo;
|
uniform sampler2D BaseTexture : hint_albedo;
|
||||||
uniform float ScalarUniform;
|
uniform float ScalarUniform;
|
||||||
|
@ -146,6 +147,7 @@ material/0 = null
|
||||||
[node name="CSGCombiner" type="CSGCombiner" parent="."]
|
[node name="CSGCombiner" type="CSGCombiner" parent="."]
|
||||||
material_override = SubResource( 10 )
|
material_override = SubResource( 10 )
|
||||||
use_collision = true
|
use_collision = true
|
||||||
|
script = ExtResource( 3 )
|
||||||
|
|
||||||
[node name="CSGBox" type="CSGBox" parent="CSGCombiner"]
|
[node name="CSGBox" type="CSGBox" parent="CSGCombiner"]
|
||||||
width = 14.0
|
width = 14.0
|
||||||
|
@ -163,10 +165,10 @@ height = 14.0
|
||||||
sides = 16
|
sides = 16
|
||||||
|
|
||||||
[node name="CSGCylinder2" type="CSGCylinder" parent="CSGCombiner"]
|
[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
|
operation = 2
|
||||||
radius = 2.0
|
radius = 2.0
|
||||||
height = 13.8871
|
height = 14.1775
|
||||||
sides = 16
|
sides = 16
|
||||||
|
|
||||||
[node name="CSGBox2" type="CSGBox" parent="CSGCombiner"]
|
[node name="CSGBox2" type="CSGBox" parent="CSGCombiner"]
|
||||||
|
|
|
@ -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)
|
19
Player.gd
19
Player.gd
|
@ -138,12 +138,17 @@ func _physics_process(delta):
|
||||||
|
|
||||||
rset("translation", translation)
|
rset("translation", translation)
|
||||||
|
|
||||||
master func on_hit():
|
master func on_hit(damage, location):
|
||||||
health -= 30
|
health -= 30
|
||||||
|
|
||||||
|
rpc("blood_splatter", location)
|
||||||
|
|
||||||
if health <= 0:
|
if health <= 0:
|
||||||
rpc("kill")
|
rpc("kill")
|
||||||
|
|
||||||
|
remote func blood_splatter(location):
|
||||||
|
pass
|
||||||
|
|
||||||
master func kill():
|
master func kill():
|
||||||
health = 0
|
health = 0
|
||||||
spawn()
|
spawn()
|
||||||
|
@ -153,7 +158,6 @@ func spawn():
|
||||||
game.get_spawn_point().spawn(self)
|
game.get_spawn_point().spawn(self)
|
||||||
|
|
||||||
func shoot():
|
func shoot():
|
||||||
|
|
||||||
var gun = find_node("Weapon")
|
var gun = find_node("Weapon")
|
||||||
|
|
||||||
gun.shoot()
|
gun.shoot()
|
||||||
|
@ -161,8 +165,6 @@ func shoot():
|
||||||
var space_state = get_world().direct_space_state
|
var space_state = get_world().direct_space_state
|
||||||
var crosshair_pos = get_viewport().size / 2
|
var crosshair_pos = get_viewport().size / 2
|
||||||
|
|
||||||
print(OS.get_real_window_size()/2)
|
|
||||||
|
|
||||||
var from = $Camera.project_ray_origin(crosshair_pos)
|
var from = $Camera.project_ray_origin(crosshair_pos)
|
||||||
var to = from + $Camera.project_ray_normal(crosshair_pos) * 1000
|
var to = from + $Camera.project_ray_normal(crosshair_pos) * 1000
|
||||||
|
|
||||||
|
@ -170,14 +172,9 @@ func shoot():
|
||||||
|
|
||||||
if "collider" in result:
|
if "collider" in result:
|
||||||
var hit = result.collider
|
var hit = result.collider
|
||||||
print(hit)
|
|
||||||
if hit.has_method("on_hit"):
|
if hit.has_method("on_hit"):
|
||||||
hit.rpc("on_hit")
|
hit.rpc("on_hit", 30, result.position)
|
||||||
else:
|
|
||||||
var effect = bulletHitEffect.instance()
|
|
||||||
effect.global_transform.origin = result.position
|
|
||||||
get_tree().root.call_deferred("add_child", effect)
|
|
||||||
|
|
||||||
|
|
||||||
func _input(event):
|
func _input(event):
|
||||||
if str(get_tree().get_network_unique_id()) != name:
|
if str(get_tree().get_network_unique_id()) != name:
|
||||||
|
|
Reference in New Issue