Cursor vector?
This commit is contained in:
@@ -1,20 +1,49 @@
|
|||||||
extends Node2D
|
extends Area2D
|
||||||
@onready var Cursor = $Cursor
|
@onready var Cursor = $Cursor
|
||||||
@export var ShowMouse = false
|
@export var ShowMouse = false
|
||||||
var old_mouse_pos = Vector2.ZERO
|
var old_mouse_pos = Vector2.ZERO
|
||||||
var mouse_velocity = Vector2.ZERO
|
var mouse_velocity = Vector2.ZERO
|
||||||
|
@export var vector_length = Vector2(50,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
|
#var speed = 5000.0
|
||||||
|
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
if not ShowMouse : Input.mouse_mode = Input.MOUSE_MODE_HIDDEN
|
|
||||||
|
#show/hide mouse
|
||||||
|
if not ShowMouse:
|
||||||
|
Input.mouse_mode = Input.MOUSE_MODE_HIDDEN
|
||||||
old_mouse_pos = get_viewport().get_mouse_position()
|
old_mouse_pos = get_viewport().get_mouse_position()
|
||||||
pass # Replace with function body.
|
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.
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
|
if is_touchingCube:
|
||||||
|
draw_vector()
|
||||||
|
else:
|
||||||
|
line_2d.clear_points()
|
||||||
|
|
||||||
|
|
||||||
var current_mouse_pos = get_viewport().get_mouse_position()
|
var current_mouse_pos = get_viewport().get_mouse_position()
|
||||||
|
|
||||||
mouse_velocity = current_mouse_pos - old_mouse_pos
|
mouse_velocity = current_mouse_pos - old_mouse_pos
|
||||||
@@ -28,3 +57,37 @@ func _process(delta: float) -> void:
|
|||||||
|
|
||||||
old_mouse_pos = current_mouse_pos
|
old_mouse_pos = current_mouse_pos
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
func _on_area_entered(area: Area2D) -> void:
|
||||||
|
if area.name == "Node2D":
|
||||||
|
print("AAAA " + str(area.name))
|
||||||
|
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.RIGHT.rotated(rotation)
|
||||||
|
var start_point = global_position
|
||||||
|
var end_point = 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
|
||||||
|
|||||||
Reference in New Issue
Block a user