Lethn Oh for crying out loud, you're right, I know exactly what I've done, I'm tired and I've mixed up the variable naming LOL.
extends Node2D
var isDragging = false
var selectedUnits = []
var dragStart = Vector2()
var selectedRectangle = RectangleShape2D.new()
func _unhandled_input(event):
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
if event.is_pressed():
if selectedUnits.size() == 0:
isDragging = true
dragStart = event.position
else:
selectedUnits = []
elif isDragging == true:
isDragging = false
queue_redraw()
var dragEnd = event.position
selectedRectangle.size = (dragEnd - dragStart).abs()
var space = get_world_2d().direct_space_state
var query = PhysicsShapeQueryParameters2D.new()
query.set_shape(selectedRectangle)
query.transform = Transform2D (0, (dragEnd + dragStart) / 2)
selectedUnits = space.intersect_shape(query)
print(selectedUnits)
for selection in selectedUnits:
print(selection)
if event is InputEventMouseMotion and isDragging == true:
queue_redraw()
func _draw():
if isDragging == true:
draw_rect(Rect2 (dragStart, get_global_mouse_position() - dragStart), Color.DARK_GREEN, false)
Instantly fixed now, thanks 😃 classic, was wondering what the hell was going on, just need to finish the tutorial now, that line you gave me is what did the trick for the initial problems, will post updated code when finished just for the sake of it being completed because this is a good tutorial.
Edit: Just needed to tweak the code a tiny bit to finish it off, will need to add other mechanics in to make it more usable.