Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
scripted rotation

nigec
Registered User
Quote
2022-05-17 09:34:23

I'm trying to make a combination lock, four numbered cylinders that rotate when clicked
I can do it with with "change rotation of scene node" then "rotate by rotation" but I can't see how to do this using a script

ccbSetSceneNodeProperty(currentNode, "Rotation",36.0,0.0,0.0 );

just turns it the first 36 degrees, I can't figure out how to add rotate by rotation

It seems easy enough to do without the script with a few variables checking turn count etc where's the fun in that
It would be nice to do my own action were I could enter a combination code and generally learn...I'm new to js and Coppercube


sven
Registered User
Quote
2022-05-17 12:06:39

nigec wrote:
I'm trying to make a combination lock, four numbered cylinders that rotate when clicked
I can do it with with "change rotation of scene node" then "rotate by rotation" but I can't see how to do this using a script

ccbSetSceneNodeProperty(currentNode, "Rotation",36.0,0.0,0.0 );

just turns it the first 36 degrees, I can't figure out how to add rotate by rotation

It seems easy enough to do without the script with a few variables checking turn count etc where's the fun in that
It would be nice to do my own action were I could enter a combination code and generally learn...I'm new to js and Coppercube



If you set it 36 then it will be 36..
it doesnt ADD 36 but sets it to be fixed 36.

to ADD 36 use this..

var OldRot=ccbGetSceneNodeProperty(currentNode, "Rotation");
var NewRot=OldRot.x +36;
ccbSetSceneNodeProperty(currentNode, "Rotation", NewRot,0,0 );


OR use variable..
variable Xrot=36;

Xrot+=36;
ccbSetSceneNodeProperty(currentNode, "Rotation",Xrot,0.0,0.0 );

If you didnt understand then feel free to ask again.. i make example if you need it.


nigec
Registered User
Quote
2022-05-17 12:27:45

Thank you sven, yes that works

is it possible to animate the rotation?


sven
Registered User
Quote
2022-05-17 12:57:27

wrote:
Thank you sven, yes that works

is it possible to animate the rotation?


I edited my door script so you see how it can be done..
Klick on box to rotate it..
You can set time (how long it should rotate)
and int value how much it should rotate.

Here is example:
https://drive.google.com/file/d/...

You can look into DoLater script to understand how this kind of stuff can work.
Probably there is many ways how to do it.(depends how you need to make it work)


nigec
Registered User
Quote
2022-05-17 15:18:12

thank you for your time,
I'm getting there, I have all the dials turning and a check to see if each dial has done a full rotation and resets the rotation back to zero once it has

very impressed with Coppercube so far


nigec
Registered User
Quote
2022-05-17 20:25:36

this is what I've come up with so far and it seems to work:

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

var node = ccbGetSceneNodeProperty(currentNode,"Name");
var rot = ccbGetSceneNodeProperty(currentNode,"Rotation");
var rotnew = rot.x+36;

if (rotnew >=360)
{
ccbSetSceneNodeProperty(currentNode, "Rotation", rot.x =0);
}
else
{
ccbSetSceneNodeProperty(currentNode, "Rotation", rotnew );
print(rot)
}

var chx1 =ccbGetSceneNodeFromName("dial1");
var chxr =ccbGetSceneNodeProperty(chx1,"Rotation");
var chx2 =ccbGetSceneNodeFromName("dial2");
var chxr2 =ccbGetSceneNodeProperty(chx2,"Rotation");
var chx3 =ccbGetSceneNodeFromName("dial3");
var chxr3 =ccbGetSceneNodeProperty(chx3,"Rotation");
var chx4 =ccbGetSceneNodeFromName("dial4");
var chxr4 =ccbGetSceneNodeProperty(chx4,"Rotation");
//code 2436
if (chxr.x==36 && chxr2.x==108 && chxr3.x==72 && chxr4.x==180)
{
print ("unlocked");
}
else
{
print("locked");
}
}



Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Internation?l" (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