Files
KevinKor01 da8f257636 Cube & Scoring Logic Part 2
Offset :
0-15 basically center (ln 42)
and anything else is left right

alignment:
0.8-1 good cut
0  basically perpendicular
-1 opposite to cut direction
2025-07-04 14:18:07 +03:00

59 lines
1.5 KiB
GDScript

extends Area2D
@export var cubeHeight = 364
@export var cursor_path: NodePath
@onready var cursor = get_node(cursor_path)
@onready var mesh_instance: MeshInstance2D = $MeshInstance2D
@onready var line = $Vector/Line2D
@onready var shape: CollisionShape2D = $HitBox
@onready var red_line = $Vector/CursorVector
@onready var green_line = $Vector/Top
@onready var pink_line = $Vector/Mid
var cube_top_center: Vector2
var CorrectHit = false
var TopScore = 0
var MidScore = 0
var BotScore = 0
@onready var area_direction
@onready var body_direction
var sliced = false
func _ready():
pass
func _on_area_entered(area: Area2D) -> void:
if area.name != "Cursor":
return
area_direction = -area.global_transform.y.normalized()
body_direction = -self.global_transform.y.normalized()
var local_pos = to_local(area.global_position)
var side_offset = local_pos.y
var alignment = area_direction.dot(body_direction)
if abs(side_offset) < 15:
print("Hit near center Slice Side offset:", round(side_offset) ," ", alignment)
elif side_offset < 0:
print("Hit to the LEFT Side, offset:", side_offset, " ", alignment)
else:
print("Hit to the RIGHT Side, offset:", side_offset, " ", alignment)
if alignment > 0.8:
print("Consider Good Cut")
func get_closest_point_on_line(line_origin: Vector2, line_dir: Vector2, point: Vector2) -> Vector2:
# Projects point onto the infinite line defined by (line_origin, line_dir)
var v = point - line_origin
var d = v.dot(line_dir)
return line_origin + line_dir * d