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
positionandworldPositionin the Needle Engine/Three.js context. - Describe scenarios where
positionandworldPositiongive different results. - Give a concise answer about whether they are the same.
- Share a minimal technical example.
Explanation:
positionis the local position of an object relative to its parent in the scene graph.worldPositionis 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
positionandworldPositionare equal. - If the object is parented,
positionis relative to its parent, butworldPositionrepresents 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
worldPositionchanges but itspositionremains 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
This topic was automatically closed 13 days after the last reply. New replies are no longer allowed.