Menu
CoddyTech

영웅: 진행 방향 바라보기

Coddy Godot 여정의 입력과 이동 섹션에 포함된 레슨. 28개 중 26번째.

영웅은 왼쪽으로 달릴 때도 여전히 오른쪽을 바라봅니다. 키가 가리키는 방향에 맞춰 Look 노드를 뒤집으세요:

if direction > 0:
	$Look.scale.x = 1
if direction < 0:
	$Look.scale.x = -1

direction을 설정한 다음에 이 줄들을 넣으세요. 아무 키도 누르지 않으면 두 if도 실행되지 않으므로 영웅은 마지막으로 바라보던 방향을 유지합니다.

challenge icon

챌린지

쉬움

주인공이 달리는 방향을 바라보게 하세요.

  1. move_and_slide() 앞에서 direction > 0일 때 $Look.scale.x를 1로 설정하세요.
  2. direction < 0일 때는 -1로 설정하세요.

‘플레이’를 누르고 왼쪽으로 달려 보세요. 주인공이 왼쪽으로 돌아서고, 멈춘 뒤에도 왼쪽을 바라봅니다. 그런 다음 ‘확인’을 누르세요.

직접 해보기

extends CharacterBody2D

var speed = 220
var acceleration = 1200
var friction = 2400
var gravity = 1000
var jump_velocity = -500

func _physics_process(delta):
	velocity.y += gravity * delta
	if Input.is_action_just_pressed("jump") and is_on_floor():
		velocity.y = jump_velocity
	var direction = Input.get_axis("move_left", "move_right")
	if direction == 0:
		velocity.x = move_toward(velocity.x, 0, friction * delta)
	else:
		velocity.x = move_toward(velocity.x, direction * speed, acceleration * delta)
	move_and_slide()

입력과 이동의 모든 레슨

직접 연습해 보세요: Godot 플레이그라운드