Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C# Vector2I inconsistent rounding behavior #75470

Closed
AlexTheRegent opened this issue Mar 29, 2023 · 1 comment · Fixed by #75477
Closed

C# Vector2I inconsistent rounding behavior #75470

AlexTheRegent opened this issue Mar 29, 2023 · 1 comment · Fixed by #75477

Comments

@AlexTheRegent
Copy link

Godot version

v4.0.1.stable.mono.official

System information

Windows 10

Issue description

In C# Vector2I conversion produces inconsistent rounding behavior. GD.PrintS((Vector2I)(new Vector2(0.5f, 0.51f)), (int)(0.5f), (int)(0.51f)); will print (0, 1) 0 0 (note that y component is rounded to 1). On the other hand, such conversion in GDScript produces consistent result, both print(Vector2i(0.5, 0.51)) and print(Vector2i(Vector2(0.5, 0.51))) will output (0, 0).
It looks like Vector2I conversion in C# uses Round() instead of Truncate() (taking into account negative values).

Steps to reproduce

Run following codes in C#:
GD.PrintS((Vector2I)(new Vector2(0.5f, 0.51f)), (int)(0.5f), (int)(0.51f));
and GDScript:
print(Vector2i(0.5, 0.51)) and print(Vector2i(Vector2(0.5, 0.51)))
then compare results.

Minimal reproduction project

N/A

@Xinhao0709
Copy link

It seems like this is due to the inconsistent behaviors between the rounding behaviors of the Vector2I conversion for C# and GDScript. We can try to use same rounding method in both languages and see if we can fix the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants