108 lines
2.7 KiB
GDScript
108 lines
2.7 KiB
GDScript
extends RigidBody3D
|
|
|
|
var despawning = false
|
|
var despawn_time_s = 10
|
|
|
|
var mesh_activated = false
|
|
var value
|
|
@export_enum("Ammo", "Stamina", "Health", "Money","Weapon") var pickup_type: int
|
|
var ammo_type
|
|
|
|
@onready var collision_shape: CollisionShape3D = $CollisionShape3D2
|
|
@onready var timer: Timer = $Timer
|
|
|
|
## MESHES
|
|
#AMMO
|
|
@onready var light_ammo: MeshInstance3D = $Meshes/Ammo/light_ammo
|
|
@onready var medium_ammo: MeshInstance3D = $Meshes/Ammo/medium_ammo
|
|
@onready var heavy_ammo: MeshInstance3D = $Meshes/Ammo/heavy_ammo
|
|
@onready var shotgun_ammo: MeshInstance3D = $Meshes/Ammo/shotgun_ammo
|
|
@onready var rocket: MeshInstance3D = $Meshes/Ammo/rocket
|
|
|
|
@onready var stamina: MeshInstance3D = $Meshes/stamina
|
|
@onready var health: MeshInstance3D = $Meshes/health
|
|
@onready var money: Node3D = $Meshes/money
|
|
|
|
|
|
var magnetable = false
|
|
var pickupable = false
|
|
var pick_up = false
|
|
var rand_amt
|
|
var player_follow
|
|
var player
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready():
|
|
|
|
if despawning == true:
|
|
timer.wait_time = despawn_time_s
|
|
timer.start()
|
|
|
|
func _physics_process(delta):
|
|
if !mesh_activated:
|
|
activate_mesh()
|
|
|
|
if player_follow != null:
|
|
if !pick_up:
|
|
if magnetable:
|
|
despawning = false
|
|
angular_velocity = lerp(angular_velocity, Vector3(0,0,0), delta)
|
|
position = lerp(position, player.item_holder.global_position, 25 * delta)
|
|
|
|
if abs(position - player.item_holder.global_position) < Vector3(.5,.5,.5):
|
|
await get_tree().create_timer(1).timeout
|
|
position = lerp(position, player.camera.global_position, .01 * delta)
|
|
await get_tree().create_timer(.01).timeout
|
|
player.pickup_apply(pickup_type,ammo_type,value)
|
|
queue_free()
|
|
|
|
func _on_timer_timeout() -> void:
|
|
if despawning == true:
|
|
collision_shape.disabled = true
|
|
await get_tree().create_timer(1).timeout
|
|
self.queue_free()
|
|
|
|
func save():
|
|
var save_dict = {
|
|
"filename" : get_scene_file_path(),
|
|
"parent" : get_parent().get_path(),
|
|
"pos_x" : position.x,
|
|
"pos_y" : position.y,
|
|
"pos_z" : position.z,
|
|
"rot_x" : rotation.x,
|
|
"rot_y" : rotation.y,
|
|
"rot_z" : rotation.z,
|
|
"linear_velocity" : linear_velocity,
|
|
"angular_velocity" : angular_velocity,
|
|
"pickup_type" : pickup_type,
|
|
"ammo_type" : ammo_type,
|
|
"value" : value
|
|
}
|
|
return save_dict
|
|
|
|
func activate_mesh():
|
|
match pickup_type:
|
|
0:
|
|
match ammo_type:
|
|
0:
|
|
light_ammo.visible = true
|
|
1:
|
|
medium_ammo.visible = true #medium
|
|
2:
|
|
heavy_ammo.visible = true #heavy
|
|
3:
|
|
shotgun_ammo.visible = true #shotgun
|
|
4:
|
|
rocket.visible = true #rocket
|
|
1:
|
|
stamina.visible = true
|
|
2:
|
|
health.visible = true
|
|
3:
|
|
money.visible = true
|
|
|
|
mesh_activated = true
|
|
|
|
func _on_magnet_timer_timeout() -> void:
|
|
magnetable = true
|