class_name Powerup extends KinematicBody enum Type { none magnet explosion superspeed swap max_pw } var mytype var initpos var speed = 0 var toggle = 0 func get_type(): return mytype func _physics_process(delta): if abs(speed) > 0.5 * delta: toggle ^= 1 if toggle: speed -= 0.01 * delta else: speed += 0.01 * delta translate(Vector3(0, speed, 0)) func _ready(): var color = Color(0, 0, 0, 0) var material = $MeshInstance.get_active_material(0).duplicate() match mytype: Type.magnet: color = Color(0, 0.8, 0.8, 1.0) material.albedo_texture = load("res://magnet.png") Type.explosion: color = Color(0.8, 0, 0, 1.0) material.albedo_texture = load("res://explosion.png") Type.superspeed: color = Color(0, 0.8, 0, 1.0) material.albedo_texture = load("res://speed.png") Type.swap: color = Color(0.8, 0.8, 0.8, 1.0) material.albedo_texture = load("res://swap.png") $MeshInstance.set_surface_material(0, material) $light.light_color = color initpos = global_transform.origin.y speed = randf() * 0.01 * (randi() & 1) * -1 translate(Vector3(0, randf() * 0.1, 0)) func _init(): mytype = randi() % (Type.max_pw - 1) + 1 add_to_group("powerup")