June 2018
Beginner to intermediate
298 pages
7h 38m
English
Now, add a script to the Character node (make sure you've saved the scene first, and the script will automatically be named Character.gd). First, define the class variables:
extends Area2Dexport (int) var speedvar tile_size = 64var can_move = truevar facing = 'right'var moves = {'right': Vector2(1, 0), 'left': Vector2(-1, 0), 'up': Vector2(0, -1), 'down': Vector2(0, 1)}onready var raycasts = {'right': $RayCastRight, 'left': $RayCastLeft, 'up': $RayCastUp, 'down': $RayCastDown}
speed will control the movement and animation speed of the character, allowing you to customize the movement speed. As you learned in Chapter 1, Introduction, using export allows you to set the value of a variable via the Inspector. Save the script ...
Read now
Unlock full access