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")
|
@export var Bullet = preload("res://objects/Bullet/Bullet.tscn")
|
||||||
@onready var neck := $CollisionShape3D/Neck
|
@onready var neck := $CollisionShape3D/Neck
|
||||||
@onready var camera := $CollisionShape3D/Neck/Camera3D
|
@onready var camera := $CollisionShape3D/Neck/Camera3D
|
||||||
|
@onready var teddyAuthority = get_multiplayer_authority()
|
||||||
var selfTeddy
|
var selfTeddy
|
||||||
var teddyParent
|
var teddyParent
|
||||||
|
|
||||||
var globalscene
|
var globalscene
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
name = str(get_multiplayer_authority())
|
name = str(teddyAuthority)
|
||||||
Global.playingGame = true
|
Global.playingGame = true
|
||||||
Global.selfTeddy = selfTeddy
|
Global.selfTeddy = selfTeddy
|
||||||
selfTeddy = self.get_path()
|
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
|
# This variable gets set my the death scene, so we know the player needs to be respawned
|
||||||
if Global.playerPleaseRespawn == true:
|
if Global.playerPleaseRespawn == true:
|
||||||
position.x = 0 #Set player X
|
position.x = 0 #Set player X
|
||||||
position.y = 1 #Set player Y
|
position.y = 10 #Set player Y
|
||||||
position.z = 0 #Set player Z
|
position.z = 0 #Set player Z
|
||||||
Global.reset_variables()
|
Global.reset_variables()
|
||||||
|
self.visible = false
|
||||||
|
|
||||||
## If player falls off the map, kill them!
|
## If player falls off the map, kill them!
|
||||||
if velocity.y < Global.playerYDeath:
|
if velocity.y < Global.playerYDeath:
|
||||||
|
@ -122,6 +124,7 @@ func remote_set_position(authority_position, bulletgenerator_position, bulletgen
|
||||||
@rpc("any_peer", "reliable")
|
@rpc("any_peer", "reliable")
|
||||||
func shoot_bullet(sound):
|
func shoot_bullet(sound):
|
||||||
var b = Bullet.instantiate()
|
var b = Bullet.instantiate()
|
||||||
|
b.set_multiplayer_authority(teddyAuthority)
|
||||||
teddyParent.add_child(b)
|
teddyParent.add_child(b)
|
||||||
b.transform = $CollisionShape3D/Neck/Camera3D/BulletGenerator.global_transform
|
b.transform = $CollisionShape3D/Neck/Camera3D/BulletGenerator.global_transform
|
||||||
b.velocity = -b.global_transform.basis.z * b.muzzle_velocity
|
b.velocity = -b.global_transform.basis.z * b.muzzle_velocity
|
||||||
|
|
|
@ -4,25 +4,26 @@ signal exploded
|
||||||
|
|
||||||
@export var muzzle_velocity = 100 # How fast the bullets are
|
@export var muzzle_velocity = 100 # How fast the bullets are
|
||||||
@export var g = Vector3.DOWN * 5
|
@export var g = Vector3.DOWN * 5
|
||||||
|
@onready var bulletAuthority = get_multiplayer_authority()
|
||||||
var velocity = Vector3.ZERO
|
var velocity = Vector3.ZERO
|
||||||
|
|
||||||
###### CHEATS
|
###### CHEATS
|
||||||
var godmode = 0
|
var godmode = 0
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
name = str("bullet ", bulletAuthority, "-0")
|
||||||
|
|
||||||
func _physics_process(delta):
|
func _physics_process(delta):
|
||||||
velocity += g * delta # Bullet gravity
|
velocity += g * delta # Bullet gravity
|
||||||
look_at(transform.origin + velocity.normalized(), Vector3.UP)
|
look_at(transform.origin + velocity.normalized(), Vector3.UP)
|
||||||
transform.origin += velocity * delta
|
transform.origin += velocity * delta
|
||||||
|
|
||||||
|
if is_multiplayer_authority():
|
||||||
for body in get_overlapping_bodies():
|
for body in get_overlapping_bodies():
|
||||||
if body.get_path() == Global.selfTeddy: # We need to modify this to make the player not invinsible
|
if body.get_path() == Global.selfTeddy: # We need to modify this to make the player not invinsible
|
||||||
pass
|
pass
|
||||||
elif body.is_in_group("human"):
|
elif body.is_in_group("human"):
|
||||||
print("Bullet hit a human player")
|
rpc("damage_player")
|
||||||
Global.playerHealth = Global.playerHealth - 10
|
|
||||||
self.queue_free()
|
|
||||||
elif body.is_in_group("AI"):
|
elif body.is_in_group("AI"):
|
||||||
print("Bullet hit an AI player")
|
print("Bullet hit an AI player")
|
||||||
body.queue_free()
|
body.queue_free()
|
||||||
|
@ -37,3 +38,9 @@ func _physics_process(delta):
|
||||||
func _on_Shell_body_entered(body):
|
func _on_Shell_body_entered(body):
|
||||||
emit_signal("exploded", transform.origin)
|
emit_signal("exploded", transform.origin)
|
||||||
queue_free()
|
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.
|
# Get the gravity from the project settings to be synced with RigidBody nodes.
|
||||||
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
|
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")
|
@export var Bullet = preload("res://objects/Bullet/Bullet.tscn")
|
||||||
|
|
||||||
func _physics_process(delta):
|
func _physics_process(delta):
|
||||||
|
if Global.selfTeddy:
|
||||||
|
player = get_node(Global.selfTeddy)
|
||||||
# Add the gravity.
|
# Add the gravity.
|
||||||
if not is_on_floor():
|
if not is_on_floor():
|
||||||
velocity.y -= gravity * delta
|
velocity.y -= gravity * delta
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
var deathTimer = 0
|
var deathTimer = 0
|
||||||
|
var teddyNode
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
|
#teddyNode = get_node(Global.selfTeddy)
|
||||||
Global.playerAlive = false
|
Global.playerAlive = false
|
||||||
|
#teddyNode.visible = false
|
||||||
if deathTimer < 100:
|
if deathTimer < 100:
|
||||||
deathTimer = deathTimer + 10 * delta
|
deathTimer = deathTimer + 10 * delta
|
||||||
if deathTimer > 100:
|
if deathTimer > 100:
|
||||||
|
|
|
@ -26,6 +26,9 @@ func _on_start_button_pressed():
|
||||||
var intMAX = int(MAX_PLAYERS)
|
var intMAX = int(MAX_PLAYERS)
|
||||||
if PORT:
|
if PORT:
|
||||||
prints("Player chose port:", intPORT)
|
prints("Player chose port:", intPORT)
|
||||||
|
if intPORT < 1024:
|
||||||
|
$mapSelected.text = "PORT CANNOT BE BELOW 1024"
|
||||||
|
else:
|
||||||
if SCENE:
|
if SCENE:
|
||||||
print("Player chose map: ", SCENE)
|
print("Player chose map: ", SCENE)
|
||||||
if MAX_PLAYERS:
|
if MAX_PLAYERS:
|
||||||
|
|
Loading…
Reference in a new issue