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

챌린지

쉬움

$Look.scale.x를 1 또는 -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()
quiz icon실력 점검

이 레슨에는 짧은 퀴즈가 포함되어 있습니다. 레슨을 시작해 문제를 풀고 진행 상황을 기록하세요.

입력과 이동의 모든 레슨

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