Hey,
I'm just starting out and I'm following a tutorial on how to make a 2d platformer.
I'm using a KinematicBody2D for the player, and a TileMap for... well, the tiles.
I have the most bare bones Player movement, but I get a weird vertical jitter when walking left and right.
Here is a video of how the player moves, and on the side are the position.y values:
https://youtu.be/nWrIXY9yld4
I'm only pressing left and right here.
here is my code:
extends KinematicBody2D
const SPEED = 60
const GRAVITY = 10
const JUMP_V = -250
const UP_DIR = Vector2(0, -1)
var velocity = Vector2()
var y # for debugging
func _physics_process(delta):
if y != position.y:
y = position.y
print(y)
if Input.is_action_pressed("ui_right"):
velocity.x = SPEED
elif Input.is_action_pressed("ui_left"):
velocity.x = -SPEED
else:
velocity.x = 0
if Input.is_action_just_pressed("ui_select"):
if is_on_floor():
velocity.y = JUMP_V
if not is_on_floor():
velocity.y += GRAVITY
velocity = move_and_slide(velocity, UP_DIR)
besides the visual jitter, I'm also unable to jump 50% of the times.
I'm using rectangles for all the collision shapes.
What can I possibly be doing wrong to cause this effect?
I'm on a mac with godot 3.2.3