project_teddy/objects/Bullet/Bullet.gd

53 lines
1.5 KiB
GDScript3
Raw Normal View History

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
@onready var bulletAuthority = get_multiplayer_authority()
2023-01-27 12:47:13 -07:00
var velocity = Vector3.ZERO
###### CHEATS
var godmode = 0
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
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"):
var playerShot = body.get_multiplayer_authority()
print("Bullet hit ", playerShot)
2023-02-28 09:46:35 -07:00
#rpc("damage_player", playerShot)
rpc_id(playerShot,"take_damage")
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()
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-24 13:43:51 -07:00
@rpc("any_peer", "call_remote", "reliable")
func damage_player(playerDamaged): # This can be used later to make sure the server and all other peers know the health of all other players
2023-02-28 09:46:35 -07:00
pass # Might use this later, or maybe not, we'll see
@rpc("any_peer", "call_remote")
func take_damage():
Global.playerHealth = Global.playerHealth - 10