Merge Move and slide into Move with a 'Collide with solids' toggle

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
rootandClaude Fable 5.1 committed 2026-09-07 15:50:52 +02:00
1 parent 6ecb20cf02
commit b0860ca07f
5 files changed
+24 -34

No files matched your search

+11 -22
View File
@@ -293,35 +293,24 @@ registerNode({
type: 'Move',
label: 'Move',
category: 'action',
description: 'Moves an object by (dx, dy) × scale × dt. Connect dt to an event\'s dt for per-second movement; leave it at 1 for per-frame.',
inputs: [exec(), obj('object'), num('dx'), num('dy'), { ...num('scale'), default: 1 }, { ...num('dt'), default: 1 }],
outputs: [exec()],
params: [],
run: (_ctx, i) => {
const target = asEntity(i.object);
if (target) {
const factor = asNumber(i.scale) * asNumber(i.dt);
target.x += asNumber(i.dx) * factor;
target.y += asNumber(i.dy) * factor;
}
return { next: 'exec' };
},
});
registerNode({
type: 'MoveAndSlide',
label: 'Move and slide',
category: 'action',
description: 'Like Move, but solid colliders of the object stop at other solid colliders and slide along them. Outputs which axes were blocked.',
description: 'Moves an object by (dx, dy) × scale × dt. Connect dt to an event\'s dt for per-second movement; leave it at 1 for per-frame. With "Collide with solids" on, the object\'s solid colliders stop at other solid colliders and slide along them; blocked x/y tell which axes hit.',
inputs: [exec(), obj('object'), num('dx'), num('dy'), { ...num('scale'), default: 1 }, { ...num('dt'), default: 1 }],
outputs: [exec(), bool('blockedX', 'blocked x'), bool('blockedY', 'blocked y')],
params: [],
run: (ctx, i) => {
params: [{ key: 'collide', label: 'Collide with solids', kind: 'boolean', default: false }],
run: (ctx, i, p) => {
const target = asEntity(i.object);
let blockedX = false;
let blockedY = false;
if (target) {
const factor = asNumber(i.scale) * asNumber(i.dt);
({ blockedX, blockedY } = ctx.moveAndSlide(target, asNumber(i.dx) * factor, asNumber(i.dy) * factor));
const dx = asNumber(i.dx) * factor;
const dy = asNumber(i.dy) * factor;
if (asBoolean(p.collide)) {
({ blockedX, blockedY } = ctx.moveAndSlide(target, dx, dy));
} else {
target.x += dx;
target.y += dy;
}
}
return { next: 'exec', outputs: { blockedX, blockedY } };
},