0 votes

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.

asked May 18 in Engine by Akluan (15 points)

1 Answer

+2 votes
Best answer

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

if traveled.length() >= bulletRange:
    queue_free()
answered May 18 by kidscancode (17,871 points)
selected May 18 by Akluan

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

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.