![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | llama |
Hello, I am new to Godot and have been reading through the documentation. I am now trying to follow the tutorial to create a game and I have hit a snag fairly early on…
This is the tutorial I am following HERE
The problem I am having is with the animation and movement. When I add the part to stop the animation, he no longer moves. The animation will play and stop when I press the arrow but it does not move at all. If take our the else statement (else: $AnimatedSprite.stop()) it moves around but as expected the animation keeps going when you stop moving.
Am I overlooking something? I found a video of this tutorial that is done the exact same way and it works in the video.
Thanks!
func process(delta):
var velocity = Vector2() # the player's movement vector
if Input.isactionpressed("uiright"):
velocity.x += 1
if Input.isactionpressed("uileft"):
velocity.x -= 1
if Input.isactionpressed("uidown"):
velocity.y += 1
if Input.isactionpressed("ui_up"):
velocity.y -= 1
if velocity.length() > 0:
velocity = velocity.normalized() * SPEED
$AnimatedSprite.play()
else:
$AnimatedSprite.stop()
position += velocity * delta
position.x = clamp(position.x, 0, screensize.x)
position.y = clamp(position.y, 0, screensize.y)
It’s hard to tell if your code is correct when the formatting is all messed up. Indent the lines here (or use the “{}” button in the post editor) to format as code.
# like this
kidscancode | 2018-05-31 05:05