I am making a game and player move ment is not right help!

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By AstroBlox

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")

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?

MattMakingAGame | 2021-10-20 05:05