0 votes

I am making a 2d platformer I want to get the best movement now the movement is so jittery Idk how to express it. but the thing is that I really don't like the current movement here is the player movement code:

    extends KinematicBody2D
var motion = Vector2()
var facing_right = true
var inair =0
const up= Vector2(0,-1)
const gravity=5
const MaxSpeed = 25
const jumpforce = 100
const accel =10
var is_dead = false
var c
func _ready():
# warning-ignore:unused_argument
func _physics_process(delta):
    if is_dead == false:
        motion.y += gravity
        if facing_right == true:
        elif facing_right ==false:

        if motion.y > MAXFALLSPEED:
            motion.y = MAXFALLSPEED
        motion.x = clamp(motion.x, -MaxSpeed, MaxSpeed)
        if Input.is_action_pressed("right"):
            facing_right = true
            motion.x += accel
        elif Input.is_action_pressed("left"):
            facing_right= false
            motion.x -= accel   
        else :
            motion.x = lerp(motion.x,0,0.2)
        if is_on_floor():
            if Input.is_action_just_pressed("jump"):
                motion.y = -jumpforce
        motion = move_and_slide(motion, up)

        if not is_on_floor():
            inair +=1
        if inair > 20:
# warning-ignore:unused_argument

var k
func _on_fallzone_body_entered(body):
    if body.get_name() == "Player":
Godot version Godot_v3.3.4-stable_win64
in Engine by (12 points)

It might be helpful to set up an Animation Tree.

HeartBeast on Youtube does a good explanation of how to set one up in his Action RPG series.


The code you have seems to work okay for me, although I don't have your artwork so it might stem from that?

Please log in or register to answer this question.

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.