0 votes

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
func _ready():
    move_lock_z = true

onready var anim_player = $Graphics/AnimationPlayer

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

# warning-ignore:return_value_discarded
    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?

Godot version 3.4.4.stable
in Engine by (23 points)

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

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.