37 lines
959 B
GDScript
37 lines
959 B
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
|
|
|
|
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.is_in_group("human"):
|
|
damage_player()
|
|
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()
|
|
|
|
func damage_player():
|
|
var damage = RandomNumberGenerator.new().randi_range(7, 16)
|
|
Global.playerHealth -= damage
|
|
Global.playerHealth
|