Overview
Are you getting lost in your games? Tired of logging your position to the console or UI? Easily toggle your position and direction with this in-game debugger!
The debugger
Features
- Keeps track of your XYZ position in the game
- Denotes a (+) if moving straight in that direction increases that value
- Denotes a (-) if moving straight in that direction decreases that value
- Lists out the direction you are currently facing
- Toggle the debugger on/off at anytime using the numberpad ‘0’ key
- NEW View block details you are currently facing
- NEW shows cross-hair when targeting block
- NEW Teleport to targeted block
- Please comment below on other ideas you’d like me to add to this debugger!
Installation / usage
In order to use this debugger, first add an If-Then logic to your player. Your If card should be Player Button, the Then do card needs to be a custom action card.
Set the Which Button option to a key you’d like to use, I chose KEYPAD_0 but you can choose a different one to your liking.
You have an option to choose the key you’d like to use for teleporting, by default it is lowercase “T”.
Lastly, paste this code in your custom action card
propEnum(“TeleportKey”, “t”, getKeyEnumValues(), {
label: “Teleport key”
})
]
const TELEPORT_DELAY = 30;
// Holds block data; used
// for the UI
function blockData(block) {
var shape = {
0: “Empty”,
1: “Box”,
2: “Triangle”,
3: “Ramp”,
4: “Corner”
};
var dir = {
0: “North”,
1: “East”,
2: “South”,
3: “West”
};
var style = {
0: “White”,
1: “Gray”,
2: “Red”,
3: “Yellow”,
4: “Green”,
5: “Cyan”,
6: “Blue”,
7: “Pink”,
8: “Light blue”,
9: “Light orange”,
10: “Salmon”,
11: “Bright red”,
12: “Burgundy”,
13: “Teal”,
14: “Blue-green”,
15: “Light pink”,
16: “Stone”,
17: “Space”,
18: “Grass”,
19: “Snow”,
20: “Dirt”,
21: “Grass/stone”,
22: “Gray craters”,
23: “Ice”,
24: “Lava”,
25: “Sand”,
26: “Water”,
27: “Wood”,
28: “Red craters”,
29: “Industrial green”,
30: “Industrial red”,
31: “Gray bricks”,
32: “Metal beige”,
33: “Red bricks”,
34: “Road”,
35: “Road w/ crossing”,
36: “Road w/ white broken line”,
37: “Road w/ yellow continuous line”,
38: “Pavement”,
39: “Pavement, concave corner”,
40: “Pavement, convex corner”
};
return {
shape: shape[block.shape],
dir: dir[block.dir],
style: style[block.style]
};
}
// Returns a list of valid keys;
// used for the card parameter
function getKeyEnumValues() {
const ret = [];
for (const keyName in KeyCode) {
ret.push({ value: KeyCode[keyName], label: keyName });
}
return ret;
}
/**
* Returns the world-space point that’s at the center of the given terrain block.
* @param {number} x Block X coordinate. In the default map size this goes from -100 to 99, but the range
* can be different in other map sizes.
* @param {number} y Block Y coordinate. From -20 to 130.
* @param {number} z Block Z coordinate. In the default map size this goes from -100 to 99, but the range
* can be different in other map sizes.
* @return {THREE.Vector3} The point at the block’s center.
*/
function getBlockCenter(x, y, z) {
return vec3(x * BLOCK_SIZE_X, (y + 0.5) * BLOCK_SIZE_Y, z * BLOCK_SIZE_Z);
}
// Ran when the “If” condition is met
export function onAction() {
if (!card.debug) {
card.debug = true;
} else {
card.debug = false;
}
}
export function onTick() {
// set to default if undefined
if (typeof card.teleporting === “undefined”) {
card.teleporting = false;
}
if (typeof card.teleportDelay === “undefined”) {
card.teleportDelay = 0;
}
// MAIN LOGIC
if (card.debug) {
var pos = getPos();
var rotation = getYaw();
var direction = “North”;
if (rotation >= -0.3925 && rotation < 0.3925) {
direction = “North”;
} else if (rotation >= 0.3925 && rotation < 1.1775) {
direction = “NorthEast”;
} else if (rotation >= 1.1775 && rotation < 1.9625) {
direction = “East”;
} else if (rotation >= 1.9625 && rotation < 2.7475) {
direction = “SouthEast”;
} else if (rotation >= -1.1775 && rotation < -0.3925) {
direction = “NorthWest”;
} else if (rotation >= -1.9625 && rotation < -1.1775) {
direction = “West”;
} else if (rotation >= -2.7475 && rotation < -1.9625) {
direction = “SouthWest”;
} else {
direction = “South”;
}
var x = Math.floor(pos.x / 2.5);
var y = Math.floor(pos.y / 2.5);
var z = Math.floor(pos.z / 2.5);
switch (direction) {
case “North”:
z = `${z}(+)`;
break;
case “NorthEast”:
z = `${z}(+)`;
x = `${x}(+)`;
break;
case “East”:
x = `${x}(+)`;
break;
case “SouthEast”:
x = `${x}(+)`;
z = `${z}(-)`;
break;
case “South”:
z = `${z}(-)`;
break;
case “SouthWest”:
z = `${z}(-)`;
x = `${x}(-)`;
break;
case “West”:
x = `${x}(-)`;
break;
case “NorthWest”:
z = `${z}(+)`;
x = `${x}(-)`;
break;
default:
break;
}
var targeting = raycastTerrain(getAimOrigin(), getAimDirection(), 50);
var coords;
if (targeting !== null) {
// The trick is to “push” the point towards the aim direction
// a bit (this is what the vec3add is doing below) because
// raycast collisions normally happen at the boundary of two
// blocks, so floating point imprecisions cause issues. By pushing
// the point a bit in the aim direction, you get reliable behavior.
targeting = vec3add(targeting, vec3scale(getAimDirection(), 0.1));
coords = getBlockCoordsAtPoint(targeting);
var targetingBlock = getBlock(coords.x, coords.y, coords.z);
// onKeyHeld was sending multiple messages;
// so I had to code up the teleporting logic
// like this
if (card.teleporting) {
card.teleportDelay++;
if (card.teleportDelay > TELEPORT_DELAY) {
card.teleportDelay = TELEPORT_DELAY;
}
}
if (card.teleportDelay === TELEPORT_DELAY) {
// reset values
card.teleportDelay = 0;
card.teleporting = false;
var modified;
// Continue to look for blocks on top of
// targeted block; if any. Warp to the
// top-most block. If you warp to a block
// with another on top of it, you fall through
// the map floor.
modified = coords;
if (getBlock(modified.x, modified.y + 1, modified.z) !== null){
modified.y++;
}
setPos(getBlockCenter(modified.x, modified.y, modified.z));
}
}
uiText(25, 100, `XYZ: ${x} / ${y} / ${z}`);
uiText(25, 120, `Direction: ${direction}`);
if (targeting !== null) {
// crosshair; 1600, 900
uiRect(790, 450, 20, 2);
uiRect(799, 441, 2, 19);
var data = blockData(targetingBlock);
uiText(25, 140, “Targeted block:”);
uiText(25, 160, ` XYZ: ${coords.x} / ${coords.y} / ${coords.z}`);
uiText(25, 180, ` Shape: ${data.shape}`);
uiText(25, 200, ` Dir: ${data.dir}`);
uiText(25, 220, ` Style: ${data.style}`);
if (card.teleporting){
uiText(25, 240, `Teleporting in ${TELEPORT_DELAY – card.teleportDelay}`);
} else {
uiText(25, 240, `Press [${props.TeleportKey}] to teleport`);
}
}
}
}
export function onKeyHeld(msg) {
if (msg.keyName === (props.TeleportKey).toLowerCase() &&
!card.teleporting) {
card.teleporting = true;
}
}
export function onResetGame() {
card.teleporting = false;
card.teleportDelay = 0;
}
Teleporting (in-action)
When you teleport, you will teleport to the top of any block your crosshair is targeting. Why? If you teleport to a block that sits below another block, you will end up falling through the map. There are also bugs when trying to teleport to smaller blocks as sometimes you won’t land on top of them.
Workshop link
Please go here to view/download the workshop link for this debugger.
NEW – you can download the card itself from here!