extends Area2D @onready var Cursor = $Cursor @export var ShowMouse = false var old_mouse_pos = Vector2.ZERO var mouse_velocity = Vector2.ZERO @export var vector_length = Vector2(500,0) @export var vector_width = 5 var line_2d : Line2D var is_touchingCube = false var collision_normal = Vector2.ZERO var collision_point = Vector2.ZERO #var speed = 5000.0 # Called when the node enters the scene tree for the first time. func _ready() -> void: #show/hide mouse if not ShowMouse: Input.mouse_mode = Input.MOUSE_MODE_HIDDEN old_mouse_pos = get_viewport().get_mouse_position() pass # Replace with function body. #setup line & properties line_2d = $Line2D line_2d.width = vector_width line_2d.default_color = Color(Color.RED) line_2d.clear_points() # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta: float) -> void: if is_touchingCube: draw_vector() else: line_2d.clear_points() var current_mouse_pos = get_viewport().get_mouse_position() mouse_velocity = current_mouse_pos - old_mouse_pos if mouse_velocity.length_squared()>0.1: rotation = lerp_angle(rotation, mouse_velocity.angle(), 80 * delta) var direction_to_mouse = (current_mouse_pos - global_position).normalized() global_position = current_mouse_pos old_mouse_pos = current_mouse_pos pass func _on_area_entered(area: Area2D) -> void: print("AAAA " + str(area.name)) if area.name == "Node2D": is_touchingCube = true draw_vector() pass # Replace with function body. func _on_area_exited(area: Area2D) -> void: if area.name == "Node2D": is_touchingCube = false pass # Replace with function body. func draw_vector(): var vector_direction = Vector2().rotated(rotation) var start_point = line_2d.to_local(global_position) var end_point = line_2d.to_local(global_position + vector_direction + vector_length) line_2d.add_point(start_point,1) line_2d.add_point(end_point,2) print("Draws the vector") pass