2023-01-27 12:47:13 -07:00
|
|
|
extends Area3D
|
|
|
|
|
|
|
|
signal exploded
|
|
|
|
|
|
|
|
@export var muzzle_velocity = 100 # How fast the bullets are
|
2023-02-07 13:25:06 -07:00
|
|
|
@export var g = Vector3.DOWN * 5
|
2023-02-23 10:19:37 -07:00
|
|
|
@onready var bulletAuthority = get_multiplayer_authority()
|
2023-01-27 12:47:13 -07:00
|
|
|
var velocity = Vector3.ZERO
|
|
|
|
|
|
|
|
|
2023-02-23 10:19:37 -07:00
|
|
|
func _ready():
|
|
|
|
name = str("bullet ", bulletAuthority, "-0")
|
2023-01-27 12:47:13 -07:00
|
|
|
|
|
|
|
func _physics_process(delta):
|
2023-02-07 13:25:06 -07:00
|
|
|
velocity += g * delta # Bullet gravity
|
2023-01-27 12:47:13 -07:00
|
|
|
look_at(transform.origin + velocity.normalized(), Vector3.UP)
|
|
|
|
transform.origin += velocity * delta
|
|
|
|
|
2023-02-23 10:19:37 -07:00
|
|
|
if is_multiplayer_authority():
|
|
|
|
for body in get_overlapping_bodies():
|
2023-03-19 16:28:17 -06:00
|
|
|
if body.get_path() == Global.selfTeddy:
|
2023-02-23 10:19:37 -07:00
|
|
|
pass
|
|
|
|
elif body.is_in_group("human"):
|
2023-02-25 15:02:26 -07:00
|
|
|
var playerShot = body.get_multiplayer_authority()
|
|
|
|
print("Bullet hit ", playerShot)
|
2023-03-02 12:52:49 -07:00
|
|
|
rpc("damage_player")
|
2023-03-06 00:35:22 -07:00
|
|
|
rpc_id(playerShot,"take_damage", Global.playerName)
|
2023-02-28 09:46:35 -07:00
|
|
|
self.queue_free()
|
2023-02-23 10:19:37 -07:00
|
|
|
elif body.is_in_group("AI"):
|
|
|
|
print("Bullet hit an AI player")
|
2023-03-19 01:56:03 -06:00
|
|
|
Global.AIHit = true
|
2023-02-23 10:19:37 -07:00
|
|
|
self.queue_free()
|
|
|
|
else:
|
|
|
|
print("Bullet hit something else")
|
|
|
|
self.queue_free()
|
2023-02-21 12:53:13 -07:00
|
|
|
await get_tree().create_timer(2).timeout
|
|
|
|
self.queue_free()
|
2023-01-27 12:47:13 -07:00
|
|
|
|
|
|
|
|
|
|
|
func _on_Shell_body_entered(body):
|
|
|
|
emit_signal("exploded", transform.origin)
|
|
|
|
queue_free()
|
2023-02-23 10:19:37 -07:00
|
|
|
|
2023-02-24 13:43:51 -07:00
|
|
|
@rpc("any_peer", "call_remote", "reliable")
|
2023-03-02 12:52:49 -07:00
|
|
|
func damage_player(): # This can be used later to make sure the server and all other peers know the health of all other players
|
|
|
|
self.queue_free()
|
2023-02-25 15:02:26 -07:00
|
|
|
|
|
|
|
@rpc("any_peer", "call_remote")
|
2023-03-06 00:35:22 -07:00
|
|
|
func take_damage(damager):
|
2023-03-10 23:24:39 -07:00
|
|
|
var damage = RandomNumberGenerator.new().randi_range(7, 16)
|
2023-03-02 12:52:49 -07:00
|
|
|
Global.playerHealth = Global.playerHealth - damage
|
2023-03-06 00:35:22 -07:00
|
|
|
Global.lastPersonToHitMe = damager
|