How to get each cornor positions of rectangle

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By blackmumba
:warning: Old Version Published before Godot 3 was released.

Because when enemies die I want them to reborn within rectangle

Sorry for my bad english :smiley:

What kind of object is the rectangle?

DodoIta | 2018-01-08 22:19

Thank you for your anwser.
Just like a window. Sorry i don’t know what kind of this rectangle called in english
but i have got an idea
just put position2d node to the top left corner and bottom right corner
and then get global position of them and random between position x and y of 2 node

var random_x = rand_range(position1.x,position2.x)
var random_y = rand_range(position1.y,position2.y)

blackmumba | 2018-01-08 23:29

:bust_in_silhouette: Reply From: Synectome

You could use the Rect2() object.
It is a rectangle defined by 2 vectors. The first Vector specifies the origin, and the second Vector specifies the opposite (diagonal) corner of the Rectangle.
This object would be useful to you as it contains methods to test for points within its perimeter.