Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
Problem spliting position

Somedude15
Guest
Quote
2024-01-19 23:44:27

Hi beautiful people, i have this piede of code i'm working on:

/*
<action jsname="action_Duplicar" description="Duplicate the position and rotation of an object">
<property name="NodeToClone" type="scenenode" description="Select the node to clone"/>
<property name="TargetNode" type="scenenode" description="Select the node to move to"/>
</action>
*/
action_Duplicar = function () {

};
action_Duplicar.prototype.execute = function (currentNode) {

var newscenenode = this.NodeToClone;
posicionVector3 = ccbGetSceneNodeProperty(this.TargetNode, "Position");
print(posicionVector3);
var [x, y, z] = posicionVector3;
print(x);
print(y);
print(z);
ccbSetSceneNodePositionWithoutCollision(newscenenode,x,y,z);
ccbSetSceneNodeProperty(newscenenode, "Rotation", (ccbGetSceneNodeProperty(this.TargetNode, "Rotation")));
};

when i do a print(posicionVector3); it returns the actual position of the object, but when i try to print the values of x,y and z it shows 0 for the 3 of them.
¿somebody knows what i'm doing wrong?

Thanks.


okeoke
Registered User
Quote
2024-01-20 06:59:33

You cant assign variables to object properties like that:
var [x, y, z] = posicionVector3;
This would only work in case positionVector3 is an array, but it is an object with properties x, y, z. You can access them like posicionVector3.x, posicionVector3.y, and posicionVector3.z;
var x = posicionVector3.x;
var y = posicionVector3.y;
var z = posicionVector3.z;
If you want to do it one line you can also do:
var [x, y, z] = [posicionVector3.x, posicionVector3.y, posicionVector3.z];
Though, I'm not sure the last one works with CopperCube version of JS engine.


Guest
Guest
Quote
2024-01-20 07:13:33

var pos = ccbGetSceneNodeProperty(cube, "Position");

ccbSetSceneNodeProperty(newCube, "Position", pos.x, pos.y, pos.z);


Somedude15
Guest
Quote
2024-01-20 15:31:30

Thanks people.


Somedude15
Guest
Quote
2024-01-20 15:34:19

Though, I'm not sure the last one works with CopperCube version of JS engine.


Yes the line
  var [x, y, z] = [posicionVector3.x, posicionVector3.y, posicionVector3.z];

Works.


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Inter?ational" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact