AI works again, bullets run as an RPC to peer

This commit is contained in:
Paul Black 2023-02-23 10:19:37 -07:00
parent 25a876f71a
commit 53ca76657f
5 changed files with 52 additions and 34 deletions

View file

@ -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

View file

@ -4,25 +4,26 @@ 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
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"):
print("Bullet hit a human player")
Global.playerHealth = Global.playerHealth - 10
self.queue_free()
rpc("damage_player")
elif body.is_in_group("AI"):
print("Bullet hit an AI player")
body.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()

View file

@ -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

View file

@ -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:

View file

@ -26,6 +26,9 @@ func _on_start_button_pressed():
var intMAX = int(MAX_PLAYERS)
if PORT:
prints("Player chose port:", intPORT)
if intPORT < 1024:
$mapSelected.text = "PORT CANNOT BE BELOW 1024"
else:
if SCENE:
print("Player chose map: ", SCENE)
if MAX_PLAYERS: