Posted December 08, 2023 by Rick Neeft
#CharacterDesign
In the past few days, I worked on a tool that allows me to create characters with Limezu’s Modern asset pack. I need a quick way to create 150 different characters for the game.
Limezu’s Modern assets pack allows for the creation of an almost unlimited amount of characters. While it comes with a tool to create characters, it does not allow the creation of a bunch of characters at once. Furthermore, it makes all the different animations. For my game, I only need the standing and sitting sprites. If I need to create a unique NPC, for example, one that walks, I will program that one.
The code can be found in on my GitHub repositoru. It will first cut out the spirtes I need. Secondly, it will generate 150 random characters. In the last step, it will merge all the characters into one big file. In my case, the file is 377KB.
In Godot, I made an NPC scene and moved the file into the project. With the animation Frame Coords, It is possible to set the x value to the location left, right, up, down, sit, etc. The y value is used to select the NPC in the file.
The following code can be used to adjust the NPC.
extends StaticBody2D
class_name default_npc
enum LookDirection {Right = 0, Up = 1, Left = 2, Down = 3}
enum NPCState {Standing, SittingBig, SittingSmall }
@export var default_position : LookDirection = LookDirection.Down
@export var default_state : NPCState = NPCState.Standing
@export var npc_index: int = 0
@export var dialogue_resource: DialogueResource
@export var dialogue_start: String = "start"
var default_look_direction: Vector2 = Vector2(3,3)
@onready var actionable = $Actionable
@onready var npc_art : Sprite2D = $Sprite
func _ready():
actionable.set_dialogue_resource(dialogue_resource, dialogue_start)
updateSprite();
func updateSprite():
default_look_direction.y = npc_index
match default_state:
NPCState.Standing:
default_look_direction.x = default_position
NPCState.SittingBig:
if (default_position == LookDirection.Right):
default_look_direction.x = 4
if (default_position == LookDirection.Left):
default_look_direction.x = 5
NPCState.SittingSmall:
if (default_position == LookDirection.Right):
default_look_direction.x = 6
if (default_position == LookDirection.Left):
default_look_direction.x = 7
npc_art.set_frame_coords(default_look_direction)