[ad_1]
The code from the place i based mostly my script.
The code i’ve has the these 2 issues:
-
The visible space for the participant to see what unit are going to be chosen would not work as meant, if i begin dragging from left to proper, and down, the choice space is drawn inverted. if i attempt to do the identical however inverting the motion the choice space is drawn appropriately.
-
The choice space and the models i wish to choose should not chosen, or simply selects only one, might need one thing to do with the issue above.
-
One thing i’ve tried is the code alone in one other scene, this baffles me as a result of it really works as meant!, it would not have any one of many drawback above
The code:
extends Node2D
var dragging = false # are we presently dragging?
var selected_units = [] # array of chosen models
var drag_start = Vector2.ZERO # location the place the drag begian
var select_rect = RectangleShape2D.new()
const blue = Colour(0.59, 0.86, 1.0,0.4)
var drag_end = Vector2.ZERO
var chosen = 0
func _unhandled_input(occasion):
if occasion is InputEventMouseButton and occasion.button_index == BUTTON_LEFT:
# When the mouse button is pressed, then the dragging begins
if occasion.pressed:
if selected_units.measurement() == 0:
dragging = true
drag_start = occasion.place
else:
for unit in selected_units:
unit.collider._set_selected(false)
selected_units = []
dragging = true
drag_start = occasion.place
elif dragging:
dragging = false
drag_end = occasion.place
replace()
drag_end = occasion.place
select_rect.extents = (drag_end - drag_start) / 2
var area = get_world_2d().direct_space_state
var question = Physics2DShapeQueryParameters.new()
question.collide_with_bodies = true
question.set_shape(select_rect)
question.rework = Transform2D(0, (drag_end + drag_start)/2)
selected_units = area.intersect_shape(question)
chosen = selected_units.measurement()
for unit in selected_units:
unit.collider._set_selected(true)
if occasion is InputEventMouseMotion and dragging:
replace()
func _draw():
if dragging:
draw_rect(Rect2(drag_start, get_global_mouse_position() - drag_start),
blue, true)
Unsure why is that occuring, now i believe that is the road the place the issue lies:
question.rework = Transform2D(0, (drag_end + drag_start)/2)
because it ‘s not inverting the realm the place we are attempting to get the models chosen. unsure if did i missed one thing to configure elsewhere? why my code fails when it is in the primary scene of my recreation however not on the check scene?
[ad_2]