MicrosoftDocs / minecraft-creator

This is the repository for Minecraft Bedrock documentation.
Creative Commons Attribution 4.0 International
184 stars 133 forks source link

Vector3 Missing #847

Open Virus5600 opened 6 months ago

Virus5600 commented 6 months ago

Version used for the module: 1.11.0-beta Minimum Engine Version: 1.20.80

Importing the Vector3 interface in an ES6M JavaScript file throws a Syntax Error saying that Vector3 does not exists. Googling left me with no answer while scouring the documentation felt useless since there's no way to identify if the said interface is available in its 1.11.0-beta or if it was changed into something else completely.

The import goes as this:

import { ..., Vector3, ...} from "@minecraft/server";

The error goes like this:

[SyntaxError: Could not find export 'Vector3' in module '@minecraft/server']

I've tried the following keywords:

So far, nothing works.


Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

Virus5600 commented 6 months ago

To anyone who might stumble here, here's a sample class I managed to create. I googled the equations and check if the methods will work properly. Feel free to modify this one as you see fit.

export default class Vector3 {
    #x;
    #y;
    #z;

    constructor(x, y, z) {
        this.#x = x;
        this.#y = y;
        this.#z = z;
    }

    length() {
        return Math.sqrt(this.#x * this.#x + this.#y * this.#y + this.#z * this.#z);
    }

    normalized() {
        let scalar = (1 / (this.length() || 1));

        this.#x *= scalar;
        this.#y *= scalar;
        this.#z *= scalar;

        return this;
    }

    static add(v1, v2) {
        return new Vector3(
            v1.x + v2.x,
            v1.y + v2.y,
            v1.z + v2.z
        );
    }

    static subtract(v1, v2) {
        return new Vector3(
            v1.x - v2.x,
            v1.y - v2.y,
            v1.z - v2.z
        );
    }

    static multiply(v1, num) {
        return new Vector3(
            v1.x * num,
            v1.y * num,
            v1.z * num
        );
    }

    static divide(v1, v2) {
        return new Vector3(
            v1.x / v2.x,
            v1.y / v2.y,
            v1.z / v2.z
        );
    }

    static distance(v1, v2) {
        return Math.sqrt(
            Math.pow(v1.x - v2.x, 2) +
            Math.pow(v1.y - v2.y, 2) +
            Math.pow(v1.z - v2.z, 2)
        );
    }

    // GETTER
    get x() { return this.#x; }
    get y() { return this.#y; }
    get z() { return this.#z; }
}