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

fix function moveToward #649

Merged
merged 1 commit into from
Jun 8, 2024
Merged

fix function moveToward #649

merged 1 commit into from
Jun 8, 2024

Conversation

datouzhu125
Copy link
Contributor

The moveToward function in GDMath class under godot.global package has wrong behavior when it goes from 0 to negative value.
I query realized the Godot source code,as follows.
static _ALWAYS_INLINE_ float move_toward(float p_from, float p_to, float p_delta) { return abs(p_to - p_from) <= p_delta ? p_to : p_from + SIGN(p_to - p_from) * p_delta; }
The implementation in Kotlin should be as follows.
fun moveToward(from: Float, to: Float, delta: Float) = if (abs(to - from) <= delta) to else from + (to - from).sign * delta

@CedNaru
Copy link
Member

CedNaru commented Jun 8, 2024

Thank you for the fix!

@CedNaru CedNaru merged commit cf2ead1 into utopia-rise:master Jun 8, 2024
45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants