What is the difference between setting worldposition and position?

Are WorldPosition and Position the same ? If not, where do they differ ?

Great question, Enthusiast!

Step-by-step plan in pseudocode:

  1. Explain the concept of position and worldPosition in the Needle Engine/Three.js context.
  2. Describe scenarios where position and worldPosition give different results.
  3. Give a concise answer about whether they are the same.
  4. Share a minimal technical example.

Explanation:

  • position is the local position of an object relative to its parent in the scene graph.
  • worldPosition is the global position of the object in the world coordinate space, factoring in all parent transforms (position, rotation, scale).

They are NOT the same:

  • If the object has no parent, then position and worldPosition are equal.
  • If the object is parented, position is relative to its parent, but worldPosition represents its absolute coordinates in the scene.

Example:

import { Behaviour, GameObject } from "@needle-tools/engine";

export class PositionDemo extends Behaviour {
    start() {
        // Get this object's local position
        const localPos = this.gameObject.position;
        // Get world position
        const worldPos = GameObject.getWorldPosition(this.gameObject);

        console.log("Local Position:", localPos);
        console.log("World Position:", worldPos);
    }
}
  • If you move a parent, the child’s worldPosition changes but its position remains the same relative to the parent.

Tip for better questions:

  • Specify if you refer to a particular API or context (e.g., Unity, Three.js, Needle Engine).
  • Ask about code examples to clarify differences.

More on the API: Three.js Object3D.position
Needle Engine Docs

Would you like an example with parent-child objects to clarify?

4 replies left
thread_Uz7llG5yZjGtU4j27FPsaRob
Reply to this post directly if you need further help (bottom right button)

Hi, the bot reply is correct generally. position is localspace in three.js so we added worldPosition to make it easier to work with worlspace coordinates if necessary

this.gameObject.worldPosition