301 Days

A year of gamedev experiments.

Day 23 - Finally Back to Normal NPCs

| Comments

Finishing bringing the NPCs into the new CellLoc reality.


NPCs back to what passes for normal

To get the multiple NPCs to fill in top-left to bottom-right, had to change the y-position calc a bit:

Assets/lib/CellLoc.cslink
34
35
36
37
38
39
40
41
42
43
44
45
46
} else {
    Vector3 position;
    int xPos = c.idx % c.dim;
    int yPos = c.idx / c.dim;
    position.x = c.x - 0.5f; // left side
    position.x += (1f / (c.dim * 2f)); // first position
    position.x += xPos * (1f / c.dim);
    position.y = (-1f) * c.y + 0.5f; // top side
    position.y -= (1f / (c.dim * 2f)); // first position
    position.y -= yPos * (1f / c.dim);
    position.z = (-0.1f) * (c.z + layer);
    return position;
}

To get the camera to the correct position looking in the right direction when we hit N:

Assets/Managers/GUIManager.cslink
25
26
27
28
29
30
if (Input.GetKeyDown (KeyCode.N)) {
    CellLoc randomNpcCell = npcManager.locateRandomNpc();
    Vector3 randomNpcPos = CLUtils.CellLocToVector3(randomNpcCell, 1);
    mainCamera.lookAtNpc(randomNpcPos);
    mapManager.UpdateZ(randomNpcCell.z);
}
Assets/CameraControlScript.cslink
95
96
97
98
public void lookAtNpc(Vector3 npcPos) {
    transform.position = new Vector3(npcPos.x, npcPos.y, npcPos.z - 15f);
    transform.LookAt(npcPos);
}

We also cached the Renderer and negated all of the z-offsets in NpcScript, and flipped the arrow image we’re using for hatred. Good enough?


Another short one today. Tomorrow we’ll do something about this:


Day 23 code - visualizer

Comments