generated from krampus/template-godot4
51 lines
1.3 KiB
GDScript
51 lines
1.3 KiB
GDScript
extends Tool
|
|
# the wimpy toothbrush
|
|
|
|
const PAINT_COLOR := Color(1, 0, 0, 0.3)
|
|
const BRUSH_SCALE := 0.2
|
|
|
|
@export var damage := 0.0063 # ~8 seconds to destroy standard nodule
|
|
|
|
@onready var raycast: RayCast3D = %Raycast
|
|
|
|
@onready var texture_idle: TextureRect = %TextureIdle
|
|
@onready var texture_used: TextureRect = %TextureUsed
|
|
@onready var brush_animation: AnimationPlayer = %BrushAnimation
|
|
|
|
@onready var resting_position: Marker3D = %RestingPosition
|
|
|
|
|
|
func _fire() -> void:
|
|
if raycast.is_colliding() and not Game.manager.is_tank_full():
|
|
brush_animation.play("brush")
|
|
var collider := raycast.get_collider()
|
|
if collider is GunkBody:
|
|
(collider as GunkBody).paint_dot(
|
|
raycast.get_collision_point(),
|
|
raycast.get_collision_normal(),
|
|
BRUSH_SCALE,
|
|
PAINT_COLOR
|
|
)
|
|
if collider is GunkNode:
|
|
(collider as GunkNode).hit(damage)
|
|
else:
|
|
brush_animation.stop()
|
|
|
|
texture_idle.visible = false
|
|
texture_used.visible = true
|
|
|
|
|
|
func _idle() -> void:
|
|
texture_idle.visible = true
|
|
texture_used.visible = false
|
|
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
hud_tool.global_basis = global_basis
|
|
|
|
var weight := clampf(HUD_ACCEL * delta, 0.0, 1.0)
|
|
var target_position := resting_position.global_position
|
|
if raycast.is_colliding():
|
|
target_position = raycast.get_collision_point()
|
|
hud_tool.global_position = hud_tool.global_position.lerp(target_position, weight)
|