# Implementing Acceleration and Deceleration in 2.5D

Attention Topic was automatically imported from the old Question2Answer platform.

Player.gd:

``````extends KinematicBody

export var JUMP_FORCE = 12
export var GRAVITY = 35
export var MAX_FALL_SPEED = 50
export var MAX_SPEED = 5
export var y_velo = 0
var facing_right = 0

#The game is a 2.5D Platformer, so I locked the Z axis
move_lock_z = true

func _physics_process(delta):
var move_dir = 0
if Input.is_action_pressed("move_right"):
move_dir += 1
if Input.is_action_pressed("move_left"):
move_dir -= 1

move_and_slide(Vector3(move_dir * MAX_SPEED, y_velo, 0), Vector3(0,1,0))

var just_jumped = false
var grounded = is_on_floor()
var roofed = is_on_ceiling()
y_velo -= GRAVITY * delta

if y_velo < -MAX_FALL_SPEED:
y_velo = -MAX_FALL_SPEED

if grounded:
y_velo = -0.1
if Input.is_action_pressed("jump"):
y_velo = JUMP_FORCE
just_jumped = true

if roofed:
y_velo = -0.1

if move_dir < 0 and facing_right:
flip()
if move_dir > 0 and !facing_right:
flip()

if just_jumped:
play_anim("jump")
elif grounded:
if move_dir == 0:
play_anim("idle")
else:
play_anim("walk")

func flip():
\$Graphics.rotation_degrees.y *= -1
facing_right = !facing_right

func play_anim(anim):
if anim_player.current_animation == anim:
return
anim_player.play(anim)
``````

how do I implement acceleration and deceleration into my 2.5D platformer game?

Have you looked at the Platformer article by Kids Can Code for any help?

Ertain | 2022-08-13 23:21