How to use behavior TileMovement
runOnStartup(async runtime => { globalThis.g_runtime = runtime })
function SimulateControl(uid, direction) {
const objectUID = g_runtime.getInstanceByUid(uid).behaviors.TileMovement;
const canMove = CanMoveTo(uid, direction)
if (canMove) objectUID.simulateControl(direction);
return canMove;
}
function CanMoveTo(uid, direction) {
const objectUID = g_runtime.getInstanceByUid(uid).behaviors.TileMovement;
const position = objectUID.getGridPosition();
const x = position[0];
const y = position[1];
let canMove = false;
switch (direction.toLowerCase()) {
case "left":
canMove = objectUID.canMoveTo(x-1,y);
break;
case "right":
canMove = objectUID.canMoveTo(x+1,y);
break;
case "up":
canMove = objectUID.canMoveTo(x,y-1);
break;
case "down":
canMove = objectUID.canMoveTo(x,y+1);
break;
default:
canMove = false;
break;
}
return canMove;
}