0 votes

extends KinematicBody2D
class_name Player

export(int) var JUMPFORCE = -225
export(int) var JUMP
RELEASEFORCE = -115
export(int) var MAX
SPEED = 100
export(int) var ACCELERATION = 20
export(int) var FRICTION = 15
export(int) var GRAVITY = 6
export(int) var ADDITIONALFALLGRAVITY = 4

var velocity = Vector2.ZERO

func physicsprocess(delta):
applygravity()
var input = Vector2.ZERO
input.x = Input.get
actionstrength("right") - Input.getaction_strength("left")

if input.x == 0:
    apply_friction()
    $AnimatedSprite.animation = "Idle"
else:
    apply_acceleration(input.x)
    $AnimatedSprite.animation = "Run"
    if input.x > 0:
        $AnimatedSprite.flip_h = false
    elif input.x < 0:
        $AnimatedSprite.flip_h = true

if is_on_floor():
    if Input.is_action_pressed("Jump"):
        velocity.y= JUMP_FORCE
else:
    $AnimatedSprite.animation = "Jump"
    if Input.is_action_just_released("Jump") and velocity.y < -80:
        velocity.y = JUMP_RELEASE_FORCE

    if velocity.y > 0:
        velocity.y += ADDITIONAL_FALL_GRAVITY

var was_in_air = not is_on_floor()
velocity = move_and_slide(velocity, Vector2.UP)
var just_landed = is_on_floor() and was_in_air
if just_landed:
    $AnimatedSprite.animation = "Run"
    $AnimatedSprite.frame = 1

func apply_gravity():
velocity.y += GRAVITY

func applyfriction():
velocity.x = move
toward(velocity.x, 0, FRICTION)

func applyacceleration(amount):
velocity.x = move
toward(velocity.x, MAX_SPEED * amount, ACCELERATION)
pass

Godot version latest
in Engine by (12 points)

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.