I am fairly new to coding and Godot in general, so try and bear with me, haha.
So I am trying to create a KinematicBody2D. I want it to have an “Asteroids Style” movement with acceleration along with some friciton to slow down the character.
It seems that the friction is not working and I am not quite sure how to implement acceleration. Should I not be using this as my method of movement? If anyone has any recommendations as to what I should do (whether it be code, learning resources, tutorials, etc), I would be greatly appreciative.
Thanks!
tl;dr: How do implement acceleration and friction?
This resets velocity every frame, that’s why friction doesn’t work. I assume the character just stops if there’s no input? So try removing this line and see if friction works then.
It might not be exactly what you want but basically if you want acceleration you have to keep adding to velocity, instead of just setting it to a fixed value.
I removed the velocity = Vector2() and the friction is working now!
Changing the velocity to += and multiplying by delta is exactly what I was looking for! I threw it all in parenthesis and added .limit_length() at the end to clamp the speed. ← That didn’t work, but adding velocity = velocity.limit_length() on a new line did.
I suppose my question now is, should I keep trying to progress by this “trial by fire” method? I watch tutorials and follow along and try to change little stuff here and there to get an understanding of what’s going on, but I can’t help but feel that there is an easier(?) way to learn this stuff.
Anyhow, I have been trying to figure this out for WEEKS now and it has been driving me crazy, haha. So thank you! I really appreciate it~
I don’t know if there’s a better way… The official documentation has tutorials “Your first 2D & 3D game” that explain the basics pretty well, though you might already know most of that stuff. Other than that it’s a lot of trial and error, figuring out stuff + looking at random places online… It can take a while for a lot of things to “click” but it’ll get easier.