AI works again, bullets run as an RPC to peer
This commit is contained in:
parent
25a876f71a
commit
53ca76657f
5 changed files with 52 additions and 34 deletions
|
@ -10,13 +10,14 @@ var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
|
|||
@export var Bullet = preload("res://objects/Bullet/Bullet.tscn")
|
||||
@onready var neck := $CollisionShape3D/Neck
|
||||
@onready var camera := $CollisionShape3D/Neck/Camera3D
|
||||
@onready var teddyAuthority = get_multiplayer_authority()
|
||||
var selfTeddy
|
||||
var teddyParent
|
||||
|
||||
var globalscene
|
||||
|
||||
func _ready():
|
||||
name = str(get_multiplayer_authority())
|
||||
name = str(teddyAuthority)
|
||||
Global.playingGame = true
|
||||
Global.selfTeddy = selfTeddy
|
||||
selfTeddy = self.get_path()
|
||||
|
@ -56,9 +57,10 @@ func _physics_process(delta):
|
|||
# This variable gets set my the death scene, so we know the player needs to be respawned
|
||||
if Global.playerPleaseRespawn == true:
|
||||
position.x = 0 #Set player X
|
||||
position.y = 1 #Set player Y
|
||||
position.y = 10 #Set player Y
|
||||
position.z = 0 #Set player Z
|
||||
Global.reset_variables()
|
||||
self.visible = false
|
||||
|
||||
## If player falls off the map, kill them!
|
||||
if velocity.y < Global.playerYDeath:
|
||||
|
@ -122,6 +124,7 @@ func remote_set_position(authority_position, bulletgenerator_position, bulletgen
|
|||
@rpc("any_peer", "reliable")
|
||||
func shoot_bullet(sound):
|
||||
var b = Bullet.instantiate()
|
||||
b.set_multiplayer_authority(teddyAuthority)
|
||||
teddyParent.add_child(b)
|
||||
b.transform = $CollisionShape3D/Neck/Camera3D/BulletGenerator.global_transform
|
||||
b.velocity = -b.global_transform.basis.z * b.muzzle_velocity
|
||||
|
|
|
@ -4,32 +4,33 @@ signal exploded
|
|||
|
||||
@export var muzzle_velocity = 100 # How fast the bullets are
|
||||
@export var g = Vector3.DOWN * 5
|
||||
|
||||
@onready var bulletAuthority = get_multiplayer_authority()
|
||||
var velocity = Vector3.ZERO
|
||||
|
||||
###### CHEATS
|
||||
var godmode = 0
|
||||
|
||||
func _ready():
|
||||
name = str("bullet ", bulletAuthority, "-0")
|
||||
|
||||
func _physics_process(delta):
|
||||
velocity += g * delta # Bullet gravity
|
||||
look_at(transform.origin + velocity.normalized(), Vector3.UP)
|
||||
transform.origin += velocity * delta
|
||||
|
||||
for body in get_overlapping_bodies():
|
||||
if body.get_path() == Global.selfTeddy: # We need to modify this to make the player not invinsible
|
||||
pass
|
||||
elif body.is_in_group("human"):
|
||||
print("Bullet hit a human player")
|
||||
Global.playerHealth = Global.playerHealth - 10
|
||||
self.queue_free()
|
||||
elif body.is_in_group("AI"):
|
||||
print("Bullet hit an AI player")
|
||||
body.queue_free()
|
||||
self.queue_free()
|
||||
else:
|
||||
print("Bullet hit something else")
|
||||
self.queue_free()
|
||||
if is_multiplayer_authority():
|
||||
for body in get_overlapping_bodies():
|
||||
if body.get_path() == Global.selfTeddy: # We need to modify this to make the player not invinsible
|
||||
pass
|
||||
elif body.is_in_group("human"):
|
||||
rpc("damage_player")
|
||||
elif body.is_in_group("AI"):
|
||||
print("Bullet hit an AI player")
|
||||
body.queue_free()
|
||||
self.queue_free()
|
||||
else:
|
||||
print("Bullet hit something else")
|
||||
self.queue_free()
|
||||
await get_tree().create_timer(2).timeout
|
||||
self.queue_free()
|
||||
|
||||
|
@ -37,3 +38,9 @@ func _physics_process(delta):
|
|||
func _on_Shell_body_entered(body):
|
||||
emit_signal("exploded", transform.origin)
|
||||
queue_free()
|
||||
|
||||
@rpc("any_peer", "call_remote", "unreliable")
|
||||
func damage_player():
|
||||
print("A bullet hit me!")
|
||||
Global.playerHealth = Global.playerHealth - 10
|
||||
self.queue_free()
|
||||
|
|
|
@ -11,10 +11,12 @@ var bulletrandom
|
|||
# Get the gravity from the project settings to be synced with RigidBody nodes.
|
||||
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
|
||||
|
||||
@onready var player = get_node(^"/root/tutorial/Teddy")
|
||||
var player
|
||||
@export var Bullet = preload("res://objects/Bullet/Bullet.tscn")
|
||||
|
||||
func _physics_process(delta):
|
||||
if Global.selfTeddy:
|
||||
player = get_node(Global.selfTeddy)
|
||||
# Add the gravity.
|
||||
if not is_on_floor():
|
||||
velocity.y -= gravity * delta
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
extends Node
|
||||
|
||||
var deathTimer = 0
|
||||
var teddyNode
|
||||
|
||||
func _ready():
|
||||
pass
|
||||
|
||||
|
||||
func _process(delta):
|
||||
#teddyNode = get_node(Global.selfTeddy)
|
||||
Global.playerAlive = false
|
||||
#teddyNode.visible = false
|
||||
if deathTimer < 100:
|
||||
deathTimer = deathTimer + 10 * delta
|
||||
if deathTimer > 100:
|
||||
|
|
|
@ -26,23 +26,26 @@ func _on_start_button_pressed():
|
|||
var intMAX = int(MAX_PLAYERS)
|
||||
if PORT:
|
||||
prints("Player chose port:", intPORT)
|
||||
if SCENE:
|
||||
print("Player chose map: ", SCENE)
|
||||
if MAX_PLAYERS:
|
||||
if intMAX < 1:
|
||||
$mapSelected.text = "MAX PLAYERS CANNOT BE NEGATIVE"
|
||||
elif intMAX > 4095:
|
||||
$mapSelected.text = "MAX PLAYERS CANNOT BE ABOVE 4095"
|
||||
else:
|
||||
print("Player chose player limit: ", intMAX)
|
||||
Networking.create_server(intPORT, intMAX)
|
||||
Networking.load_map(SCENE)
|
||||
Networking.add_player_node(1)
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
else:
|
||||
$mapSelected.text = "NO MAX PLAYERS SELECTED"
|
||||
if intPORT < 1024:
|
||||
$mapSelected.text = "PORT CANNOT BE BELOW 1024"
|
||||
else:
|
||||
$mapSelected.text = "NO MAP SELECTED"
|
||||
if SCENE:
|
||||
print("Player chose map: ", SCENE)
|
||||
if MAX_PLAYERS:
|
||||
if intMAX < 1:
|
||||
$mapSelected.text = "MAX PLAYERS CANNOT BE NEGATIVE"
|
||||
elif intMAX > 4095:
|
||||
$mapSelected.text = "MAX PLAYERS CANNOT BE ABOVE 4095"
|
||||
else:
|
||||
print("Player chose player limit: ", intMAX)
|
||||
Networking.create_server(intPORT, intMAX)
|
||||
Networking.load_map(SCENE)
|
||||
Networking.add_player_node(1)
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
else:
|
||||
$mapSelected.text = "NO MAX PLAYERS SELECTED"
|
||||
else:
|
||||
$mapSelected.text = "NO MAP SELECTED"
|
||||
else:
|
||||
$mapSelected.text = "NO PORT SPECIFIED"
|
||||
|
||||
|
|
Loading…
Reference in a new issue