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
This commit is contained in:
2025-07-04 14:18:07 +03:00
parent 4ebfb16ca7
commit da8f257636

View File

@@ -25,18 +25,7 @@ var BotScore = 0
var sliced = false var sliced = false
func _ready(): func _ready():
pass
var shape_size = Vector2.ZERO
if shape.shape is RectangleShape2D:
shape_size = shape.shape.extents * 2 # extents are half-size
elif shape.shape is CapsuleShape2D:
shape_size = Vector2(shape.shape.radius * 2, shape.shape.height)
# Add other shape types as needed
# Now use actual height
var cube_height = shape_size.y
func _on_area_entered(area: Area2D) -> void: func _on_area_entered(area: Area2D) -> void:
if area.name != "Cursor": if area.name != "Cursor":
@@ -47,15 +36,19 @@ func _on_area_entered(area: Area2D) -> void:
var local_pos = to_local(area.global_position) var local_pos = to_local(area.global_position)
var side_offset = local_pos.y # this is the offset *perpendicular* to Area2D's facing var side_offset = local_pos.y
var alignment = area_direction.dot(body_direction) var alignment = area_direction.dot(body_direction)
if abs(side_offset) < 5: if abs(side_offset) < 15:
print("Hit near center Top", " ", alignment) print("Hit near center Slice Side offset:", round(side_offset) ," ", alignment)
elif side_offset < 0: elif side_offset < 0:
print("Hit to the LEFT Side, offset:", side_offset, " ", alignment) print("Hit to the LEFT Side, offset:", side_offset, " ", alignment)
else: else:
print("Hit to the RIGHT Side, offset:", side_offset, " ", alignment) 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: func get_closest_point_on_line(line_origin: Vector2, line_dir: Vector2, point: Vector2) -> Vector2: