Files
2D-Beatsaber-game/game/Scripts/CursorScript.gd

97 lines
2.0 KiB
GDScript3
Raw Normal View History

2025-07-01 22:05:29 +03:00
extends Area2D
@onready var Cursor = $Cursor
@export var ShowMouse = false
var old_mouse_pos = Vector2.ZERO
var mouse_velocity = Vector2.ZERO
2025-07-01 22:18:04 +03:00
@export var vector_length = Vector2(500,0)
2025-07-01 22:05:29 +03:00
@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:
2025-07-01 22:05:29 +03:00
#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.
2025-07-01 22:05:29 +03:00
#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:
2025-07-01 22:05:29 +03:00
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:
2025-06-29 22:19:02 +03:00
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
2025-07-01 22:05:29 +03:00
func _on_area_entered(area: Area2D) -> void:
2025-07-01 22:18:04 +03:00
print("AAAA " + str(area.name))
2025-07-01 22:05:29 +03:00
if area.name == "Node2D":
2025-07-01 22:18:04 +03:00
2025-07-01 22:05:29 +03:00
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():
2025-07-01 22:18:04 +03:00
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)
2025-07-01 22:05:29 +03:00
line_2d.add_point(start_point,1)
line_2d.add_point(end_point,2)
print("Draws the vector")
pass