Hello, I’ve been trying to make a pickup item called crayon where my drawing line is drawn from the tip of the crayon, however I expereinced problems with my script and I have no idea how to make the line draw from the sprite called “dot” which is at the tip of the crayon, can anyone help me with this?
This script would be for your crayon node:
@onready var dot = $"dot"
@export var lines_parent: Node
# lines_parent can be anything in your scene thats static
# you could also use get_tree().current_scene instead as parent
@export var line_scene: PackedScene
@export var line_resolution: float = .1 ##time until new point gets added
var is_drawing: boolean:
get:
return is_drawing
set(value):
if value != is_drawing and value:
create_new_line()
is_drawing = value
var current_line: Line2D = null
func create_new_line():
current_line = line_scene.instantiate()
current_line.add_point(Vector2.ZERO)
lines_parent.add_child(current_line)
tick_loop()
func tick_loop():
while(is_drawing):
tick()
await get_tree.create_time(line_resolution).timeout
func tick() -> void:
is_drawing = Input.is_action_pressed("draw_action")
#your action (defined in the project settings)
if (is_drawing):
current_line.add_point(dot.global_position - current_line.global_position)
This is the script for the line scene instance:
@export var time_alive: float = 2 ## time until point gets deleted
func _ready():
dissolve_loop()
func dissolve_loop:
if (get_point_count == 0):
queue_free()
return
await get_tree().create_timer(time_alive).timeout
remove_point_at(0)
dissolve_loop()