Skip to content

Instantly share code, notes, and snippets.

@AnderRasoVazquez
Forked from PLyczkowski/target_picker.gd
Created November 10, 2018 01:40
Show Gist options
  • Save AnderRasoVazquez/f39d73ed9df9179f67064c6e89550eae to your computer and use it in GitHub Desktop.
Save AnderRasoVazquez/f39d73ed9df9179f67064c6e89550eae to your computer and use it in GitHub Desktop.
extends Control
# Settings
var arrow_body_sprites_amount = 15
var scale_change = 0.03
# Nodes
onready var path_2d = $Path2D
onready var arrow_head = $Path2D/Head
# Resources
var ArrowBody = preload("res://card_engine/target_picker/path_follow_arrow_body.tscn")
func _ready():
# Arrow Body
for x in arrow_body_sprites_amount:
# Skip the last two to make space for head
if x in [arrow_body_sprites_amount, arrow_body_sprites_amount -1]: continue
# Add arrow body element
var arrow_body = ArrowBody.instance()
path_2d.add_child(arrow_body)
arrow_body.set_meta("target_unit_offset", 1.0 / arrow_body_sprites_amount * float(x))
# Set scale
arrow_body.scale.x -= scale_change * (arrow_body_sprites_amount - x)
arrow_body.scale.y -= scale_change * (arrow_body_sprites_amount - x)
# Arrow Head
arrow_head.set_meta("target_unit_offset", 0.95)
path_2d.move_child(arrow_head, path_2d.get_child_count())
func _process(delta):
var mouse_position = get_tree().get_root().get_mouse_position()
path_2d.curve.set_point_position(1, mouse_position)
update_arrow_bodies()
func update_arrow_bodies():
# Get curve lenght
var current_path_2d_lenght = path_2d.curve.get_baked_length()
# Update offset according to current curve lenght
for arrow_body in path_2d.get_children():
arrow_body.offset = current_path_2d_lenght * arrow_body.get_meta("target_unit_offset")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment