0 votes

Hi!
I want a KinematicBody2D to shoot and move towards a point not at the same time. I tried this inside the _fixed_process callback updating the time elapsed using delta: firing works fine but calling the move function moves the sprite really fast, and I can't seem to slow it down. This is the code I use for motion:

var movement = direction.normalized() * speed
move(movement)

where speed is set at 1.0. Decreasing it only reduces the distance walked, not its speed. Can anyone help me fix this behviour? It looks like a simple issue but I have few experience with Godot :)

in Engine by (570 points)

1 Answer

+1 vote
Best answer

Remember the linear movement equation?
∆s = V*∆t
In this case, the movement in a frame is ∆s and the time between frames named "delta" (a really low value) is ∆t.
Fixing your movement equation should be:

 movement = direction.normalized() * speed * delta

You normalize the directional vector because you want it to be always one unit long.

This way, you should have a "speed" displacement in "direction" when time sums 1.

by (7,934 points)
selected by

I catually tried this but it kept giving me an error and I didn't investigate. Turns out I wasn't initializing the speed variable :p
So... thanks, it works!

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.