The slime of #296 walks to three kinds of point: a spot in its home area, home again, and the player. Each of those took about eight nodes, and Distance measured between local positions, so it was wrong for the player, whose sprite sits inside a container. - New node Move toward: steps an object toward a world point by at most speed times dt and stops exactly on it. Below a moved or turned parent the step is turned into the axes Move counts in. - With Collide with solids it moves the way Move does. Outputs are arrived, the distance still left and hit. - Distance now measures in world units, however deep each object is nested. The slime itself, its state machine, the player's lives and the change to the Break animation live in the project, not in the repo. Tests: - Gate on melektaus-atx: 220 files, 3442 tests (3436 + 6), CHECK EXIT 0. - Six new catalog cases. Both counter-checks bite: Distance back to local positions fails one, Move toward without the parent's axes fails one. - No e2e module touches these nodes. The e2e sum stays at 1701. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
23 lines
754 B
TypeScript
23 lines
754 B
TypeScript
import { worldPositionOf } from '../../NodeContext';
|
||
import type { NodeDef } from '../../NodeRegistry';
|
||
import { asEntity } from '../../values';
|
||
import { num, obj } from '../shared';
|
||
|
||
export const Distance: NodeDef = {
|
||
type: 'Distance',
|
||
label: 'Distance',
|
||
category: 'data',
|
||
description: 'Distance between two objects, in world units – however deep each one is nested.',
|
||
inputs: [obj('a'), obj('b')],
|
||
outputs: [num('result')],
|
||
params: [],
|
||
run: (_ctx, inputs) => {
|
||
const a = asEntity(inputs.a);
|
||
const b = asEntity(inputs.b);
|
||
if (!a || !b) return { outputs: { result: 0 } };
|
||
const pa = worldPositionOf(a);
|
||
const pb = worldPositionOf(b);
|
||
return { outputs: { result: Math.hypot(pa.x - pb.x, pa.y - pb.y) } };
|
||
},
|
||
};
|