Godot Version
4.2.1
Intro
I’m making a game where you have to put something down at just the right angle.
The thing on which you put it down (the holder), is set at a difference angle every new game in degrees between 0 and 360. But let’s not take that in account and assume it’s just at 0 degrees.
The thing you put down (the item) is rotating slowly and once it touches the holder, rotation will stop and the difference should be calculated.
It doesn’t matter if the item is rotated 180 degrees and put down on the holder or if it’s at a 0 degrees difference.
This is what I have so far:
no_1 is the item.rotation_degrees.y
no_2 is the holder.rotation_degrees.y
func calculate_difference(no_1, no_2):
if no_1 >= 180:
no_1 -= 180
if no_2 >= 180:
no_2 -= 180
if no_1 > no_2:
return no_1 - no_2
else:
return no_2 - no_1
First of all, the two if statements at the top don’t work, somehow. So when rotating_degrees is bigger than 180, it doesn’t subtract 180.
And second, I don’t know how to take in account that if the item is rotated at 350 degrees, the difference should be 10 degrees. And not 350 or with the -180 rule, 170 degrees.
Question
So how should I go about this, to work out the difference and take in account that the item can either be at 0 or 180 degrees and that, for example, a result of 352 degrees is actually really close?
I’m very much a beginner when it comes to Godot, so please excuse any obvious mistakes.