How can I make my shooting area be a circle, not square?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Akluan

I have a projectile being fired, and previously used a timer to make it disappear, but I’m working on having different stats like speed and range. I’ve changed to using the following code to make my projectile only go a set distance from where it starts:

func range_check():
traveled = (self.global_position-origin)
if traveled.x >= bulletRange:
	queue_free()
elif traveled.y >= bulletRange:
	queue_free()
elif traveled.y <= -bulletRange:
	queue_free()
elif traveled.x <= -bulletRange:
	queue_free()

this results in a square basically, as shooting diagonally goes further. I would like it to feel like more of a circle and I’m not quite sure how to go about this.

:bust_in_silhouette: Reply From: kidscancode

traveled is already a distance, don’t split it into x and y.

if traveled.length() >= bulletRange:
    queue_free()

oh my god thank you, I’ve only ever thought of .length() in the context of like strings or lists not space. perfect, thanks so much

Akluan | 2020-05-18 23:32

Specifically in this context, “length” is the magnitude of the vector.

kidscancode | 2020-05-18 23:34