What is Actor
? Maybe this should be KinematicBody2D
? (just guessing)
the rest looks good to me...
why are you doing:
func getinput():
velocity = Vector2(0, 100) # <------
?
Are you sure isonfloor is ever true? (just add print(is_on_floor())
somewhere, and see the output)
2 Recommandations:
.
1. you are defining you constants as integers. Then you use them to calculate velocity which is a Vector2 (2 floats). In your case, this works perfectly fine, but can lead to horrifix bugs, that are hard to find.
Try this, and you'll understand:
print(1 / 10) # Output: 0
print(1.0 / 10.0) # Output: 0.1
.
2. You should not change velocity
in you get_input()
.
It's work and is fine, if you have very simple scripts, but makes debugging harder as it should be.
It's better to calculate a relative Vector2 to your actual velocity, return it, and set/add/wahtever it to the actual velocity:
velocity += get_input()
OR
give velocity as an argument, calculate stuff, return it, and set it to the new velocity:
velocity = get_input(velocity)
why?
if you change variables in functions, it becomes very fast very unclear what happens to variables and there values where and when.
If you use the return, it's very clear what happens to the velocity at that point.
In this case it's extra missleading, because the function is "getinput". This should get the input and not "calculatenew_velocity". Hope you get what i mean.