0 votes
extends KinematicBody2D

var movespeed : int = 80

var interactDist : int = 70

var vel : Vector2 = Vector2()
var facingDir : Vector2 = Vector2()

onready var animationPlayer = $AnimationPlayer

onready var rayCast = get_node('Raycast2D')

func physicsprocess(delta):

vel = Vector2()

#inputs
if Input .is_action_pressed("KeyUp"):
    vel.y -=1
    facingDir = Vector2(0, -1)
    animationPlayer.play("RunUp")
if Input .is_action_pressed("KeyDown"):
    vel.y +=1
    facingDir = Vector2(0, 1)
    animationPlayer.play("RunDown")
if Input .is_action_pressed("KeyLeft"):
    vel.x -=1
    facingDir = Vector2(-1, 0)
    animationPlayer.play("RunLeft")
if Input .is_action_pressed("KeyRight"):
    vel.x +=1
    facingDir = Vector2(1, 0)
    animationPlayer.play("RunRight")

if Input .is_action_just_released("KeyRight"):
    vel.x +=1
    facingDir = Vector2(1, 0)
    animationPlayer.play("IdleRight")

if Input .is_action_just_released("KeyLeft"):
    vel.x -=1
    facingDir = Vector2(-1, 0)
    animationPlayer.play("IdleLeft")

if Input .is_action_just_released("KeyUp"):
    vel.y -=1
    facingDir = Vector2(0, -1)
    animationPlayer.play("IdleUp")

if Input .is_action_just_released("KeyDown"):
    vel.y +=1
    facingDir = Vector2(0, 1)
    animationPlayer.play("IdleDown")

# normalized the velocity to prevent faster diagonal movement

vel = vel.normalized()

# move the player
move_and_slide(vel * movespeed)

see this happens

in Engine by (12 points)

uh, what happens. there's nothing on the question that tells us the problem, were you trying to post a gif? Also, if you could put four spaces in front of all your code lines, they would be put in a code box and be much more readable. :)

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.