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 MAXFALLSPEED = 50
const MaxSpeed = 25
const jumpforce = 100
const accel =10
var is_dead = false
var c
#-------------------------
func _ready():
    pass
# warning-ignore:unused_argument
func _physics_process(delta):
    if is_dead == false:
        motion.y += gravity
        if facing_right == true:
            $Sprite.scale.x=1
        elif facing_right ==false:
            $Sprite.scale.x=-1

        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
            $AnimationPlayer.play("Run")
        elif Input.is_action_pressed("left"):
            facing_right= false
            motion.x -= accel   
            $AnimationPlayer.play("Run")
        else :
            motion.x = lerp(motion.x,0,0.2)
            $AnimationPlayer.play("Idle")
        if is_on_floor():
            inair=0
            if Input.is_action_just_pressed("jump"):
                motion.y = -jumpforce
                $AnimationPlayer.play("Jump")
        motion = move_and_slide(motion, up)

        if not is_on_floor():
            inair +=1
        if inair > 20:
            $AnimationPlayer.play("fall")
# warning-ignore:unused_argument

var k
func _on_fallzone_body_entered(body):
    if body.get_name() == "Player":
        k=get_tree().change_scene("res://Death.tscn")
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.

https://youtu.be/Z9aR9IiiHT8

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 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 webmaster@godotengine.org with your username.