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:
elif traveled.y >= bulletRange:
elif traveled.y <= -bulletRange:
elif traveled.x <= -bulletRange:

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.

in Engine by (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:
by (18,435 points)
selected by

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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.