Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Help with CopperCube
How to enable/disable bahavior dynamicaly?

Alireza
Guest
Quote
2020-05-31 21:00:51

For example :
We put " object controlled by keyboard" behavior to cubmesh.
In some conditions want to enable, and in some other become disable.is it possible?


Robo
Guest
Quote
2020-05-31 23:15:53

Behaviors generally run all the time or at least have a 'delta' time which runs just like an every xxxx ms time delay.

Your best to create an action instead of a behavior as they can be controlled much easier to only run that as needed.


Alireza
Guest
Quote
2020-06-01 00:14:42

Robo wrote:
Behaviors generally run all the time or at least have a 'delta' time which runs just like an every xxxx ms time delay.

Your best to create an action instead of a behavior as they can be controlled much easier to only run that as needed.

Thanks dear Robo
In fact, I need different values ​​of parameter speed rotation of "object controlled by keyboard". I thought I could create different behaviors and replace them over time by enable/disable it. That you said it's not possible. So what should I do?


Robo
Guest
Quote
2020-06-01 01:43:06

You can modify my custom rotate action below if you like. It takes in CC variables 'storageItem' (the object to rotate) and 'lidAxis' (x,y or z to rotate about). It uses a fixed rotation of 8 degrees and uses 'lid' variable as either open or close.

Just remove what you don't need and adjust to suit what you want. If you have trouble keep at it and over time understand how this weird function with this and me...sort of works...


action_RotateDoor = function() {};

action_RotateDoor.prototype.execute = function() {
var me = this;
this.registeredFunction = function()
{ me.rotate();
};

// on start function
ccbRegisterOnFrameEvent(this.registeredFunction);
this.item = ccbGetCopperCubeVariable("storageItem");
this.axis = ccbGetCopperCubeVariable("lidAxis");
this.storage = ccbGetSceneNodeFromName(this.item);
this.door = ccbGetChildSceneNode(this.storage,0);
this.type = ccbGetCopperCubeVariable("lid");
if (this.type == "open") {
this.rot = 0;
} else if (this.type == "close") {
this.rot = 8;
}
}

// run on every frame
action_RotateDoor.prototype.rotate = function() {
var me = this;
if (me.type == "open") me.rot = me.rot+0.32; // 25 frames
if (me.type == "close") me.rot = me.rot-0.5; // 16 frames
if (me.axis == "y") ccbSetSceneNodeProperty(me.door, "Rotation", 0,me.rot,0);
if (me.axis == "x") ccbSetSceneNodeProperty(me.door, "Rotation", me.rot,0,0);
if (me.axis == "z") ccbSetSceneNodeProperty(me.door, "Rotation", 0,0,me.rot);

if (me.type == "open" && me.rot >= 8) {
ccbUnregisterOnFrameEvent(this.registeredFunction);
}
if (this.type == "close" && this.rot <= 0.5){
ccbUnregisterOnFrameEvent(this.registeredFunction);
}
}


Alireza
Guest
Quote
2020-06-01 04:52:42

Robo wrote:
You can modify my custom rotate action below if you like. It takes in CC variables 'storageItem' (the object to rotate) and 'lidAxis' (x,y or z to rotate about). It uses a fixed rotation of 8 degrees and uses 'lid' variable as either open or close.

Just remove what you don't need and adjust to suit what you want. If you have trouble keep at it and over time understand how this weird function with this and me...sort of works...


action_RotateDoor = function() {};

action_RotateDoor.prototype.execute = function() {
var me = this;
this.registeredFunction = function()
{ me.rotate();
};

// on start function
ccbRegisterOnFrameEvent(this.registeredFunction);
this.item = ccbGetCopperCubeVariable("storageItem");
this.axis = ccbGetCopperCubeVariable("lidAxis");
this.storage = ccbGetSceneNodeFromName(this.item);
this.door = ccbGetChildSceneNode(this.storage,0);
this.type = ccbGetCopperCubeVariable("lid");
if (this.type == "open") {
this.rot = 0;
} else if (this.type == "close") {
this.rot = 8;
}
}

// run on every frame
action_RotateDoor.prototype.rotate = function() {
var me = this;
if (me.type == "open") me.rot = me.rot+0.32; // 25 frames
if (me.type == "close") me.rot = me.rot-0.5; // 16 frames
if (me.axis == "y") ccbSetSceneNodeProperty(me.door, "Rotation", 0,me.rot,0);
if (me.axis == "x") ccbSetSceneNodeProperty(me.door, "Rotation", me.rot,0,0);
if (me.axis == "z") ccbSetSceneNodeProperty(me.door, "Rotation", 0,0,me.rot);

if (me.type == "open" && me.rot >= 8) {
ccbUnregisterOnFrameEvent(this.registeredFunction);
}
if (this.type == "close" && this.rot <= 0.5){
ccbUnregisterOnFrameEvent(this.registeredFunction);
}
}


I don't know how to thank you for being worthy of you.
It's great. I will definitely use it.
Just two questions?
Are the functions you wrote independent of the frame rate?
Can I use these functions in combination with"object controlled by keyboard" behavior? For example, can I set the rotation speed(of obj controlled by keyboard) to 0 , and use your code instead?
Honestly, I'm going to simulate the movement of the vehicle using the "object or person controlled by keyboard". But the problem is that I can't control the rotation parameter of this behavior
thank you in advance


Robo
Guest
Quote
2020-06-07 02:46:30

I cant seem to find the behavior - 'object controlled by keyboard' so cant say whether its an on frame event or based on delta time (set X ms delay).

My action runs on every frame yes.
I'm not sure about whether you can have more than instance of running every frame action/behavior - yet to test this out..


Create reply:


Posted by: (you are not logged in)


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