8-way movement in an isometric 2d game with the AnimatedSprite node
Hello there, i am a beginner in game development and right now i am learning the basics.
Because i love the isometric view in games i am using the isometric dungeon tileset vom kenny.nl to learn on isometric game design in Godot and i wanted to animate the player figure in the way that the player can move in all of the 8 directions.
So i have prepared the animations with the animation editor but only 4 of the 8 run animations are working properly in the code. The same goes for the idle animation (which basically is only one frame).
I was searching in the Godot documentation and on YouTube to find a solution but i couldn't find any.
The animations which are working fine are the left, right, up and down run animations and also the idle animation.
This is the code of the movement which is working:
extends KinematicBody2D export (int) var speed = 200 var velocity = Vector2() func get_input(): # get_global_mouse_position() velocity = Vector2() if Input.is_action_pressed("right"): velocity.x += 1 $AnimatedSprite.play("run_right") if Input.is_action_just_released("right"): $AnimatedSprite.play("idle_right") if Input.is_action_pressed("left"): velocity.x -= 1 $AnimatedSprite.play("run_left") if Input.is_action_just_released("left"): $AnimatedSprite.play("idle_left") if Input.is_action_pressed("down"): velocity.y += 1 $AnimatedSprite.play("run_down") if Input.is_action_just_released("down"): $AnimatedSprite.play("idle_down") if Input.is_action_pressed("up"): velocity.y -= 1 $AnimatedSprite.play("run_up") if Input.is_action_just_released("up"): $AnimatedSprite.play("idle_up") velocity = velocity.normalized() * speed func _physics_process(delta): get_input() velocity = move_and_slide(velocity)
And i was trying this snippet here for the diagonal directions but it's not working:
if Input.is_action_pressed("right") and Input.is_action_pressed("down"): $AnimatedSprite.play("run_d_right_down") if Input.is_action_just_released("right") or Input.is_action_just_released("down"): $AnimatedSprite.play("idle_d_right_down")
Does someone maybe knows what i am doing wrong? I thought i could maybe solve the problem by adding a key-combination of s + d in the input map but it seems that setting up two keys for one command does only work with combinations like alt + s and so on.
I hope it is ok if i am asking a second question towards movement additionally.
My idea for the movement of the player charakter is a combination of keyboard and mouse controls. I basically would like to use the mouse for the direction the playersprite is facing and on which he is performing it's actions. So let's say the player character can face an enemy because the player is moving the mouse cursor in the direction of the enemy. At the same time the player should also be able to move forward or backwards or sideway.
I was looking today a few hours for documentations and YouTube material and so on to achieve this kind of movement but haven't found any. Maybe i was overlooking thoseparts of the documentation? I was also playing around with the "get_global_mouse_position" method but that was looking quite strange.
If someone could help me out that would be cool.
And please excuse my clumsy english, i am not a native speaker.