0 votes

Hi. I'm porting an early project into Godot 4, and my knockback/attack-dash stopped working, the move_toward function is not moving the knockback vector to zero like in Godot 3.5. It's a 3D game.

Code example from 3.5 where it works inside the attack function:

knockback_vector = knockback_vector.move_toward(Vector3.ZERO, 50 * delta)
knockback_vector = move_and_slide(knockback_vector)

The knockback_vector is the last input direction if you attack, and one between you and your enemy when you get attacked so I can reutilize the code.

This was the latest attempt at Godot 4:

velocity = knockback_vector.move_toward(Vector3.ZERO, 50 * delta)
velocity += knockback_vector

The move_toward is not reducing knockback to 0 like this, is there a bug or am I blatantly wrong in this approach?

Godot version 4
in Engine by (46 points)

1 Answer

0 votes
Best answer

Solved, just had to try some more stuff

        knockback = knockback.move_toward(Vector3.ZERO, 50 * delta)
        velocity.x = move_toward(knockback.x, 0, delta)
        velocity.z = move_toward(knockback.z, 0, delta)

This worked just like I wanted it.

by (46 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.