Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
clone cube

just_in_case
Moderator
Quote
2024-03-29 15:09:41

Hi @Derty, it seems that @Sam is right about cloning the node, but it seems that you want them specifically to be distinct from each other that is they should not share the same properties or the same behavior.
I can understand why it is needed, but clones shares all the behaviors that is attached to them. It is better not to use the behaviors on the node itself that you are cloning, instead put the behaviors if they allow you to work without having to be attached to current node,then attach the behavior to different nodes.
It is better to use or create custom extension or behaviors so that you can create individual properties that you can alter for the clone.


As I can see you are trying to create a strategy game, I also had tried creating a clone of age of empires Realtime Strategy game, and in there, you can check that out, how the game is created, and what the code look likes, and how all the villagers in that game are same but have distinct features the only thing is that the game was in 2D you need to modify or alter the code to implement similar features for 3D.

here is the link to the CCB file of the game, I had updated it a lot, but unfortunately I don't have the updated project as that was lost during a ransomware attack in past. but here is the project that was on my G-Drive:-

https://drive.google.com/file/d/...


new object
Guest
Quote
2024-03-29 15:32:25

Okay, I've created an example where I clone a node and place it where I collide by a ray from my camera.
To start, I place my functions into 'Before first drawing, do something' as shown in this image:
🔎︎



new object
Guest
Quote
2024-03-29 15:33:31

And then I add left and right mouse buttons for cloning and selecting these clones.
When I select a clone, I just change its scale to show that I've chosen the right node on click:
🔎︎

So when I press the right button, I create a clone and place it in the collision position between the camera and the mouse position projection in 3D:

let targ = ccbGet3DPosFrom2DPos(ccbGetMousePosX(), ccbGetMousePosY());
let cpos = ccbGetSceneNodeProperty(ccbGetActiveCamera(), "PositionAbs");
cloneNode("newObject", ccbGetCollisionPointOfWorldWithLine(cpos.x,cpos.y,cpos.z, targ.x,targ.y,targ.z));

And change the scale of the selected node by pressing the left button:

getSelectedNode();
if(selectedNode) ccbSetSceneNodeProperty(selectedNode, "Scale", 2,2,2);



derty
Guest
Quote
2024-03-29 15:50:38

excellent, it works thanks, and is it possible to clone their programming too? meaning if I clone a cube that behaves as it does or do I have to give it other instructions via javascript?


new object
Guest
Quote
2024-03-29 16:26:23

You can try to set some behavior to the original node, but that really slows down performance. As I always say, you should assess the situation and determine exactly what you need from this node. In some cases, you can use behavior on the original node, but for others, you should work with clones from elsewhere.


Create reply:


Posted by: (you are not logged in)


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