Hi all,
I have an Area2d with a Line2d node like his, see below. But now i want to convert this straight line to a smoothed Vector line. How to approach this?
extends Node2D
onready var Globals := get_node("/root/Globals")
onready var SCREEN = Globals.setupScreen()
onready var pressed = false
const MINIMAL_DISTANCE_POINT := 50
var rocketpath_is_drawn := false
signal rocket_curve(points)
var historyPoint := Vector2(0,0)
func _ready():
init_area2d()
func init_area2d():
$Area2D/CollisionShape2D.position.x = 0
$Area2D/CollisionShape2D.position.y = 0
$Area2D/CollisionShape2D.shape.extents.x = SCREEN.width
$Area2D/CollisionShape2D.shape.extents.y = SCREEN.height
func _on_Area2D_input_event(_viewport, event, _shape_idx):
if event is InputEventMouseButton and !rocketpath_is_drawn:
if event.pressed:
pressed = true
pass
if not event.pressed:
pressed = false
rocketpath_is_drawn = true
emit_signal("rocket_curve", $Line2D.points)
if event is InputEventMouseMotion:
if pressed:
if historyPoint.distance_to(event.position) > MINIMAL_DISTANCE_POINT:
make_line(event)
func make_line(event):
historyPoint = event.position
$Line2D.add_point(historyPoint)