Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Help with CopperCube
Rotation=..., then do something

Monks
Guest
Quote
2024-10-19 08:31:02

Hi guys, can someone please come up with an action or procedure where if an object rotation is for example equal to 0,90,0 a specific action should be carried out


okeoke
Registered User
Quote
2024-10-19 09:26:23

// The following embedded xml is for the editor and describes how the behavior can be edited:
// Supported types are: int, float, string, bool, color, vect3d, scenenode, texture, action
/*
<behavior jsname="behavior_ExecuteOnRotation" description="Execute on Rotation">
<property name="minThreshold" type="float" default="89" />
<property name="maxThreshold" type="float" default="91" />
<property name="normalize" type="bool" default="true" />
<property name="axis" type="string" default="y" />
<property name="execute" type="bool" default="true" />
<property name="actionToExecute" type="action" default="" />
</behavior>
*/

var behavior_ExecuteOnRotation = function () {
this.wasExecuted = !this.execute;
};

behavior_ExecuteOnRotation.prototype.onAnimate = function (node, timeMs) {
var rot = ccbGetSceneNodeProperty(node, 'Rotation');
var curRotValue = rot[this.axis];

if (this.normalize) {
curRotValue = this.normalizeAngle(curRotValue);
}

if (this.wasExecuted) {
if (curRotValue < this.minThreshold || curRotValue > this.maxThreshold) {
this.wasExecuted = false;
}
} else {
if (curRotValue >= this.minThreshold && curRotValue <= this.maxThreshold) {
ccbInvokeAction(this.actionToExecute, node);
this.wasExecuted = true;
}
}
}

behavior_ExecuteOnRotation.prototype.normalizeAngle = function (angle) {
return (angle + 360) % 360;
}


minThreshold - minimal angle for action to be executed;
maxThreshold - maximal angle for action to be executed;
normalize - should normalize angle to keep it between 0 and 360 or not
axis - axis which you track, should be x, y, or z;
execute - should action be executed if initial rotation is inside threshold value or not
actionToExecute - action to execute


okeoke
Registered User
Quote
2024-10-19 09:29:15

it replaces "execute" with "execute" for some reason.


okeoke
Registered User
Quote
2024-10-19 09:34:14

What the hell? You can't type
🔎︎
inside the post?


Monks
Guest
Quote
2024-10-19 12:05:32

Thanks for you attention okeoke, must I alternate the code or it is flawless?


okeoke
Registered User
Quote
2024-10-19 12:12:25

Np. Try if it works for you. If it does not - it should be modified or fixed, if not I guess it's ok:)


serge
Registered User
Quote
2024-10-28 05:17:34

@okeoke can you send as a script


okeoke
Registered User
Quote
2024-10-28 08:26:01

Sure. Script and test ccb:https://drive.google.com/file/d/...


serge
Registered User
Quote
2024-10-28 10:58:14

Thank you


serge
Registered User
Quote
2024-10-28 11:00:50

I though this was an action script.


Create reply:


Posted by: (you are not logged in)


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