I'm using a script based on a tutorial I found on Youtube for my RTS game and it works great. Only problem is it only selects a maximum of 32 units. The "(selected.size())" also only returns that number, despite many more units being within the rectangle boundaries. Does anyone have any idea what the problem could be?
func _unhandled_input(event):
if globalvar.build_mode == false:
if event is InputEventMouseButton and event.button_index == BUTTON_LEFT:
if event.pressed:
selected = []
dragging = true
drag_start = get_global_mouse_position()
elif dragging:
dragging = false
select_draw.update_status(drag_start, get_global_mouse_position(), dragging)
var drag_end = get_global_mouse_position()
select_rectangle.extents = (drag_end - drag_start) / 2
var space = get_world_2d().direct_space_state
var query = Physics2DShapeQueryParameters.new()
query.set_shape(select_rectangle)
query.transform = Transform2D(0, (drag_end + drag_start)/2)
selected = space.intersect_shape(query)
print(selected.size())
for unit in selected:
if globalvar.paused == 0:
if unit.collider.visible == true:
for unit_collider in unit:
if unit.collider.is_in_group("Unit"):
if unit.collider.is_player == 1:
if selected.size() > 1:
globalvar.selected_unit = null
globalvar.selected_structure = null
globalvar.selected_livestock = null
globalvar.selected_resource = null
globalvar.selected_animal = null
unit.collider.select()
ui_unit._update()
if selected.size() == 1:
globalvar.selected_unit = null
globalvar.selected_structure = null
globalvar.selected_livestock = null
globalvar.selected_resource = null
globalvar.selected_animal = null
globalvar.selected_unit = unit.collider
ui_unit._update()
if unit.collider.is_player == 0:
if unit.collider.visible == true:
if selected.size() == 1:
globalvar.selected_unit = null
globalvar.selected_structure = null
globalvar.selected_livestock = null
globalvar.selected_resource = null
globalvar.selected_animal = null
globalvar.selected_unit = unit.collider
ui_unit._update()
if dragging:
if event is InputEventMouseMotion:
select_draw.update_status(drag_start, get_global_mouse_position(), dragging)
pass