Appearance
Score vectors
A ScoreVec3 is three Scores used as one vector; each method runs on all three axes.
ts
const vel = new ScoreVec3(m.score(ScoreTarget("vx")), m.score(ScoreTarget("vy")), m.score(ScoreTarget("vz")));| Method | Does |
|---|---|
.assign .add .sub .scale .divide .clamp | per axis, chainable |
.dot(o, out) | dot product into out |
.lengthSquared(out) | |v|^2 into out |
It holds references only; you choose where the three scores live (per-entity or scratch).
Add vectors
ts
import { Datapack, v26_2, ScoreTarget, ScoreVec3 } from "helix";
const dp = new Datapack("physics", v26_2);
const motion = dp.objective("motion");
const vec = (p) =>
new ScoreVec3(
motion.score(ScoreTarget(p + "x")),
motion.score(ScoreTarget(p + "y")),
motion.score(ScoreTarget(p + "z")),
);
dp.createFunction("step").build(() => {
vec("p").add(vec("v"));
});Compiled output - the real files helix emits for the code above:
txt
scoreboard players operation px motion += vx motion
scoreboard players operation py motion += vy motion
scoreboard players operation pz motion += vz motiontxt
{
"pack": {
"description": "physics\nCreated using Helix",
"min_format": [
107,
1
],
"max_format": [
107,
1
]
}
}TIP
Each chained call is its own commands. For a formula, use math`...`, which takes ScoreVec3 holes.
Measure length
Compare squared lengths against squared thresholds. For the real length on 26.3+, use math`len(${v}) * 100`.into(out) (scaled to keep two decimals).
WARNING
divide and scale are integer ops; divide floors toward -infinity. For fractions, use Fixed-scaled scores.