How Set WorldPosition?

this.gameObject.worldPosition = new Vector3(0,5,0); //work
this.gameObject.worldPosition.set(0,5,0);//dont work

Hi oot4chi! I’m an AI powered assistant here to help you with questions about Needle Engine, three.js, and basic Unity or Blender help. Please reply with your question, and also provide your OS, Needle Engine version, and any Unity or Blender version you’re using for further assistance!

2 replies left - GPT 4O
thread_C6xq7IbBJsJrI2pFt25344mj
Reply to this message to continue the conversation

needle engine 3.47.10

Thank you for the details, oot4chi.

To set the worldPosition in Needle Engine, your first line of code works because it directly assigns a new Vector3 instance to worldPosition. The second line tries to use set, which does not modify the existing instance in a way that affects worldPosition.

Here’s a proper way to set the worldPosition using the set method correctly:

// Retrieve current position
const currentPos = this.gameObject.worldPosition;

// Update position using set
currentPos.set(currentPos.x, this.top, currentPos.z);

// Assign the updated position back
this.gameObject.worldPosition.copy(currentPos);

This will effectively change the worldPosition. If you have more questions or need additional examples, feel free to ask!

1 replies left - GPT 4O
thread_C6xq7IbBJsJrI2pFt25344mj
Reply to this message to continue the conversation

why local position can use setter

this.gameObject.position.set(0,5,0);//work

Hi oot4chi! In Needle Engine, the position property of the game object often utilizes a direct property setter, which allows you to call the set method on the Vector3 instance directly. This is why this.gameObject.position.set(0, 5, 0); works.

The position property may create a new instance or perform specific updates internally, allowing the change to reflect directly.

However, the worldPosition might not have the same behavior due to how it’s implemented. In most cases, you will need to create a new Vector3 instance or copy values into it for worldPosition.

If you have further questions or need clarification, let me know!

0 replies left - GPT 4O
thread_C6xq7IbBJsJrI2pFt25344mj
Reply to this message to continue the conversation

because worldPosition doesnt exist in three.js and it is a getter/setter. The explanation is a bit more complex - what you can do however is as a workaround to just set the modified worldPosition again:

this.gameObject.worldPosition = this.gameObject.worldPosition.set(0,1,0);