Are WorldPosition and Position the same ? If not, where do they differ ?
Great question, Enthusiast!
Step-by-step plan in pseudocode:
- Explain the concept of
position
andworldPosition
in the Needle Engine/Three.js context. - Describe scenarios where
position
andworldPosition
give different results. - Give a concise answer about whether they are the same.
- 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
andworldPosition
are equal. - If the object is parented,
position
is relative to its parent, butworldPosition
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 itsposition
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