Hello!
Hoping to help one of my developers with getting collisions to work with the websocket API. The way that the code is currently written, whenever we interact with a statue in our test, the collisions seem to only be set for a single tile. The game.setImpassable functions we use seem to wipe out any prior collision setting, so only the last function ends up working. We tried to match the syntax from the chopping trees example code, but we haven’t got this to work yet. Any insights are greatly appreciated!
Thank you!
Kevin
//Main code
const runSocks = () => {
game.subscribeToEvent("playerInteracts", (data, _context) => {
const statueID = parseInt(data.playerInteracts.objId);
const doorID_ONE = locationToId[`${DOOR_ONE.x},${DOOR_ONE.y}`];
const doorID_TWO = locationToId[`${DOOR_TWO.x},${DOOR_TWO.y}`];
console.log(`Statue ${statueID} statueID was triggered by`, _context?.player?.name ?? _context.playerId);
let statueState = game.partialMaps[MAP_ID].objects?.[statueID].normal;
let doorOneState = game.partialMaps[MAP_ID].objects?.[doorID_ONE].normal;
let doorTwoState = game.partialMaps[MAP_ID].objects?.[doorID_TWO].normal;
statueState == STATUE.off? statueState = STATUE.on : statueState = STATUE.off;
doorOneState == DOORS.close? doorOneState = DOORS.open : doorOneState = DOORS.close;
game.engine.sendAction({
$case: "mapSetObjects",
mapSetObjects: {
mapId: MAP_ID,
objects: {
[statueID]: {
normal: statueState,
highlighted: statueState,
customState: statueState == STATUE.off? "statue-off" : "statue-on",
_tags: [],
},
},
},
});
game.engine.sendAction({
$case: "mapSetObjects",
mapSetObjects: {
mapId: MAP_ID,
objects: {
[doorID_ONE]: {
normal: doorOneState,
highlighted: doorOneState,
customState: doorOneState == DOORS.close? "door-close" : "door-open",
_tags: [],
},
},
},
});
game.engine.sendAction({
$case: "mapSetObjects",
mapSetObjects: {
mapId: MAP_ID,
objects: {
[doorID_TWO]: {
normal: doorOneState,
highlighted: doorOneState,
customState: doorOneState == DOORS.close? "door-close" : "door-open",
_tags: [],
},
},
},
});
if (doorOneState == DOORS.close) {
game.setImpassable(MAP_ID, DOOR_ONE.x, DOOR_ONE.y, true);
game.setImpassable(MAP_ID, DOOR_TWO.x, DOOR_TWO.y, true);
} else {
game.setImpassable(MAP_ID, DOOR_ONE.x, DOOR_ONE.y, false);
game.setImpassable(MAP_ID, DOOR_TWO.x, DOOR_TWO.y, false);
}
});