0 votes

when the AnimatedSprite move its only playing one frame.I Make all frames and make a looooooooong scripts but its only works one frame i recheck but it doesn't so any solution?
this is a top down game
Here my script,

` extends KinematicBody2D

export (int) var speed = 200

var velocity = Vector2()

func getinput():
velocity = Vector2()
if Input.is
actionpressed("uiright"):
velocity.x += 1
$AnimatedSprite.play("Runside")
else:
$AnimatedSprite.play("Idle")
if Input.isactionpressed('uileft'):
velocity.x -= 1
$AnimatedSprite.play("Runside")
if Input.is
actionpressed('uidown'):
velocity.y += 1
$AnimatedSprite.play("rundown")
if Input.isactionpressed('ui_up'):
velocity.y -= 1
$AnimatedSprite.play("Runup")
velocity = velocity.normalized() * speed

func physicsprocess(delta):
getinput()
velocity = move
and_slide(velocity)`

note:I am a total noob at scripting and making games pls help
Edit:sorry p7f i cannot see a button in tool but i see {} which make no sense

in Engine by (21 points)
edited by

Would you share a project so i can check? Also, i recommend you that when you paset code here, you use the code sample format (there is a button in the toolbar when you write messages) So we can understand it.

when player press wasd it only works one frame that i made

Do you know how to share the project because this is my first time in Q&A also i cant upload any images really

1 Answer

+1 vote
Best answer

Hi,
you need to copy your code correctly as there is some typos that affect the code, however, i can see in your code that you initial velocity is Vector2() ,(and repeated 2 times in your script) , that means velocity.x = 0 and velocity.y = 0 , and the last line you need to check the correct variables, you are missing some.

I would recommend just to look the step by step 1st game of godot docs, the explain what just I mentioned but more clear.

good luck

by (196 points)
selected by

it worked Thank you

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.