title | c3p | hasDemo | deprecated | preview | tags | date | |||||
---|---|---|---|---|---|---|---|---|---|---|---|
How to use behavior TileMovement |
how-to-use-behavior-tile-movement-20.06.07.c3p |
true |
true |
preview.png |
|
|
- c3p how-to-use-behavior-tile-movement-20.06.07.c3p
- demo link
- Patreon link
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;
}