Could the "await get_tree().create_timer(0.04).timeout" instead just be "await get_tree().physics_frame"? I think that's all you need in order to wait for the collision physics to catch up to the changes you're making in moving the collision shape. Also, I'd be interested in seeing how this would be done in a 3D way, if it's at all different.
I thought the same at first, but it didn't always work with a await physical frame alone. I think with 2 await physic frames it was ok. And then I decided to add something safe to the video :) 3d variant is now on my list.
Thanks! But how do you select one unit only? With func _select_one_unit(): var currentMouse = get_global_mouse_position() for body in currentMouse: if body in get_tree().get_nodes_in_group("unit"): body.selected = true and input call I am getting a delay, so I have to click longer. Can't get it.
You only have to put the area2D on the mouse position and downsize the collision shape of the area. like this (not tested): func _select_one_unit(): selection_area.global_position = get_global_mouse_position() collision_shape_2d.shape.size = Vector2.ONE # maybe more? await get_tree().create_timer(0.04).timeout var units = get_tree().get_nodes_in_group("unit") for body in selection_area.get_overlapping_bodies(): if body in units: body.selected = true units.erase(body) for body in units: body.selected = false
Thanks for this toturial. But i found that i coundn't select unit. When i open "Show collision area", the collision area doesn't move when i am selecting units. I want to ask is this a problem?
yeah this is a problem. die Collision shape of the "SelectionArea" should move after the selection. the "_select_units" function ensures that the collision moves, adjusts its size and selects the units in the collision
@@DevDrache Thank you. The collision shape's problem was solved. But it show error in func _get_rect_start_positon(),it show that "Invalid assignment of property or key 'x' with value of type 'float' on a base object of type 'Nil'.".If i change it to "var newPosition : Vector2", the start position of the collision shape will always be (0,0). Also, units still can not be selected.
thanks for this toturial
thank you very much!
DevDrache podes hacer algo perecido a Mario Bros montando a Yoshi gracias por los tutoriales
Do you mean the part where Mario jumps on Yoshi and uses him?
@@DevDrache si esa versión porque no hay muchos tutoriales que lo expliquen bien gracias por los tutoriales de siempre
sure, i put it on my list :)
@@DevDrache gracias
Could the "await get_tree().create_timer(0.04).timeout" instead just be "await get_tree().physics_frame"? I think that's all you need in order to wait for the collision physics to catch up to the changes you're making in moving the collision shape.
Also, I'd be interested in seeing how this would be done in a 3D way, if it's at all different.
I thought the same at first, but it didn't always work with a await physical frame alone.
I think with 2 await physic frames it was ok.
And then I decided to add something safe to the video :)
3d variant is now on my list.
Thanks!
But how do you select one unit only?
With
func _select_one_unit():
var currentMouse = get_global_mouse_position()
for body in currentMouse:
if body in get_tree().get_nodes_in_group("unit"):
body.selected = true
and input call
I am getting a delay, so I have to click longer. Can't get it.
You only have to put the area2D on the mouse position and downsize the collision shape of the area.
like this (not tested):
func _select_one_unit():
selection_area.global_position = get_global_mouse_position()
collision_shape_2d.shape.size = Vector2.ONE # maybe more?
await get_tree().create_timer(0.04).timeout
var units = get_tree().get_nodes_in_group("unit")
for body in selection_area.get_overlapping_bodies():
if body in units:
body.selected = true
units.erase(body)
for body in units:
body.selected = false
How do i add a click to move the units? When you just click it clears the units.
The following video explains it:
th-cam.com/video/L03UWTLF9kw/w-d-xo.html
It's basically part 2
Thanks for this toturial. But i found that i coundn't select unit. When i open "Show collision area", the collision area doesn't move when i am selecting units. I want to ask is this a problem?
yeah this is a problem.
die Collision shape of the "SelectionArea" should move after the selection.
the "_select_units" function ensures that the collision moves, adjusts its size and selects the units in the collision
@@DevDrache Thank you. The collision shape's problem was solved. But it show error in func _get_rect_start_positon(),it show that "Invalid assignment of property or key 'x' with value of type 'float' on a base object of type 'Nil'.".If i change it to "var newPosition : Vector2", the start position of the collision shape will always be (0,0). Also, units still can not be selected.
@@DevDrache i think it is the problem of selectionStartPoint. i use print to check it. i dont know why it is always (0,0).
@@DevDrache Oh i fix it.I reversed the order of two lines of code.Thank you so much.
good work :)