extends CharacterBody2D
@onready var sprite = $AnimationPlayer
@onready var joystick = $"../joystick"


var speed = 300

var walk_animations = [
"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h"
]

var current_animation = "idle"

func _physics_process(delta):
var direction = joystick.posVector
var animation_index = direction.angle() / (PI / 4)

if animation_index < 0:
animation_index += 8

current_animation = walk_animations[animation_index]

if direction:
velocity = direction * speed
else:
velocity = Vector2(0, 0)
current_animation = "idle"

sprite.play(current_animation)
move_and_slide()

๋ฆฌํ€˜ ์ค€๊ฑฐ make this into 4 direction movement

๊ฒฐ๊ณผ

1ebec223e0dc2bae61abe9e7468370700fbaad7567e727c9d99c90a34f76ed5b6e8dc72c68af260ec0cabde379f7

func _physics_process(delta):
var direction = joystick.posVector
var animation_index = direction.angle() / (PI / 2)

if direction.length() > 0:
current_animation = walk_animations[animation_index]
velocity = direction.normalized() * speed
else:
current_animation = "idle"
velocity = Vector2.ZERO

sprite.play(current_animation)
move_and_slide(velocity)

๋ญํ•˜๋…ธ
๋˜๋Š” ์–ธ์–ด๋ฅผ ๋‹ฌ๋ผ๋‹ˆ๊น
๋ง‰์ƒ ๊ฒŒ์ž„ ๋งŒ๋“œ๋ ค๋ฉด ์ˆ˜์ •ํ•ด์•ผ ๋˜๋Š”
์–ธ์–ด๋ฅผ ์ฃผ๋„ค

๋‹ˆ๊ฐ€ ๊ตฌ๊ธ€ ai ๋ณด๋‹ค ๋ชปํ•˜๋ฉด ๋ชปํ•œ๋‹ค๋Š”๊ฒŒ ์ฆ๋ช…๋จ
๊ตฌ๊ธ€ bard์— ๋ฌผ์–ด๋ณธ๋‹ค๋ฉด

1ebec223e0dc2bae61abe9e7468370700fbaad7567e727c9d99c97a34c72ed5b87e99b1c18a4cceab9e825051d87

๋ฌด์Šจ ๊ตฌ๊ธ€ bard ๋‚ด๊ฐ€ ์ฒ˜์Œ ์จ๋ดค์„ ๋•Œ
๋‹น์‹œ ์„ฑ๋Šฅ์ด๋„ค ์ฝ”ํŒŒ์ผ๋Ÿฟ ์ด๊ฑฐ๋Š”


- dc official App