project_teddy/objects/Bullet/Bullet.gd
2023-02-24 13:43:51 -07:00

46 lines
1.2 KiB
GDScript

extends Area3D
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"):
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()
func _on_Shell_body_entered(body):
emit_signal("exploded", transform.origin)
queue_free()
@rpc("any_peer", "call_remote", "reliable")
func damage_player():
print("A bullet hit me!")
Global.playerHealth = Global.playerHealth - 10
self.queue_free()