- Edited
So, I noticed mod operator is not working the way I thought.
For example.
GDScript Output:
4 % 24 = 4
-4 % 24 = -4
Python Output:
4 % 24 = 4
-4 % 24 = 20
I wonder if Godot´s mod operator works differently with negative numbers
So, I noticed mod operator is not working the way I thought.
For example.
4 % 24 = 4
-4 % 24 = -4
4 % 24 = 4
-4 % 24 = 20
I wonder if Godot´s mod operator works differently with negative numbers
Correct. GDScript % matches C %, unfortunately. For the equivalent of Python % use the posmod function. See here: https://docs.godotengine.org/en/3.5/classes/class_%40gdscript.html#class-gdscript-method-posmod
Best to use wrapi()
for most things modulo is typically used for. It'll behave as expected.