Topic was automatically imported from the old Question2Answer platform.
Asked By
Aaron Franke
How can I create a selection rectangle, and select the units inside, in a 3D RTS? The following are not separate questions, but elaborations of my confusions and ideas of how such a system could work:
Is there a way that I can get all 3D objects inside of an area on the screen/viewport?
Is there a way that I can raycast from the screen into the world?
Should I create a rectangle on the viewport with Control or Node2D nodes?
Hi, as I comment in the post that you reference, you need to get a rect2 box first to make the check. Then, you has to unproject the position of your character from the camera object:
var character_pos = character.get_translation()
var unprojected_pos = cameraObj.unproject_position(character_pos)
With this and your preview rect you can check if is inside of the rectangle.
var rectSelectionBox = Rect2(bla, bla,..,..) #fill with correct values ;)
var contains = rectSelectionBox.has_point(unprojected_pos)
Check the steps in the other post to get the rect2, that was I did and works. All this was made in Godot 2, so , I don’t know if will work in Godot3.