The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

This might be a dumb question. But I want to convert an x-value between a positive integer and negative integer into a degree value between 0 and 360. (or a radian value between 0 and 2pi) For a radius of 2000, 2000 would be 360 degrees, 0 would be 180 degrees, -1000 would be 90 degrees, etc. (Imagine a line wrapped around a circle.) Maybe I'm just extraordinarily dumb because my brain just can't figure this out.

in Engine by (67 points)

1 Answer

0 votes

Take a look at range_lerp(). That'll map a given value within some input range to a corresponding value within some output range.

https://docs.godotengine.org/en/stable/classes/[email protected]#class-gdscript-method-range-lerp

I'm not sure I follow your example exactly, but it seems that you're trying to map a value in the range of -2000 to 2000 to the range of 0 to 360. Here's an example of that:

print(range_lerp(2000, -2000, 2000, 0, 360))
print(range_lerp(0, -2000, 2000, 0, 360))
print(range_lerp(-1000, -2000, 2000, 0, 360))

Output:

360
180
90
by (22,674 points)
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 Frequently asked questions and 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 [email protected] with your username.