Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
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? |
||||
|
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. |
||||
|
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? |
||||
|
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); } } |
||||
|
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 |
||||
|
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.. |
|