Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
clone cube

derty
Guest
Quote
2024-03-28 15:55:05

how you can clone a cube inside the game and be able to select it as for a strategic game


new object
Guest
Quote
2024-03-28 16:18:40

I don't quite understand what you mean by using it for a strategy game, but you can easily clone it using the function ccbCloneSceneNode.

You can create a clone in a variable like this:
var clone = ccbCloneSceneNode(nodeThatYouCloned);


Then, you can perform any actions you want with this node.

For more information on how to do this, could you provide more details about what exactly you need to do with this clone?


derty
Guest
Quote
2024-03-28 16:24:54

Normal cloning doesn't allow me to distinguish the cubes I clone. If I wanted to select cloned cubes, I would only select the original one and that's a problem. I just need an example on how to clone it and distinguish it


new object
Guest
Quote
2024-03-28 16:29:40

var cloneNodeCount = 0;
var clone = ccbCloneSceneNode(nodeThatYouCloned);
ccbSetSceneNodeProperty(clone, "Name", "name_" + cloneNodeCount);
cloneNodeCount += 1;

That allows you to define a different name for each cloned node, and then select it by the needed name.
But you still need to provide more information.


derty
Guest
Quote
2024-03-28 16:36:39

of course the cubes must behave as units and this has already been done. I just have to clone them and put them in a specific point like a base so when I press the button to create the cube soldiers they are different and I can select them to give them the commands that I will then insert. Is it possible to also define a position after cloning? I'm using this but it doesn't work after cloning them

var p = ccbGetSceneNodeFromName("cube");
ccbSetSceneNodePositionWithoutCollision(p, 39.016857, 22.383883, -12.144409);


new object
Guest
Quote
2024-03-28 16:43:58

You're using cbSetSceneNodePositionWithoutCollision, so you're using the "Collide when moved" behavior, right? Because if you're not, you should set the basic property by
ccbSetSceneNodeProperty(clone, "Position", newPositionVector);



new object
Guest
Quote
2024-03-28 16:45:27

But you still need to provide a better explanation of what this node is and how it's supposed to work. After that, I can give you a more complex example of code.


derty
Guest
Quote
2024-03-28 16:54:59

As explained, it is a cube soldier who attacks the player when he sees it but when I put time to clone him and this has already been done I would like the cube soldier to clone himself in a specific position and have the possibility of being selected to give him the commands problem is that with normal cloning I can't select the cubes because it only selects the original cloned cube. I need to be able to select the other cloned cubes


new object
Guest
Quote
2024-03-28 17:06:39

What method of node selection are you using?


derty
Guest
Quote
2024-03-29 01:30:13

a simple one I click on the cube I give it a variable and from there I let it do what I'm interested in, dock, move etc etc. all I need is that when it is cloned it can be distinct and different so that if I click on it and give it a command the other clones don't execute it.


new object
Guest
Quote
2024-03-29 11:59:48

Let's see.
First of all, you said:
click on the cube

Are you using the default behavior of CopperCube, or did you write your own? Because with clones, it's better to write specific behavior.
Next, you mentioned:
I give it a variable and from there I let it do what I'm interested in

Are you creating a variable based on the name of the exact clone, or is there some other way?

For now, I see one solution based on what you've told me. When you create a clone, place it into a specific node as a child. Then, when you try to select something, use a for loop on click to search if the mouse hits each clone inside this parent node. This will allow you to get the needed clone, and then you can manipulate it as you wish.


derty
Guest
Quote
2024-03-29 14:02:35

that's right I'm using default commands with coppercube. Is there a way to do it in code? clone and make them different from each other? Thank you


new object
Guest
Quote
2024-03-29 14:48:26

Here's the pseudocode I wrote to illustrate the basic principle of what I'm talking about. It works well in the engine and demonstrates how to clone a node and select (get the node into a variable) a clone by clicking on it.


var parentNodeForClone = ccbGetSceneNodeFromName("folderForCloneNodes"); // Define the parent node where cloned nodes will be inserted
var nodeForCloning = ccbGetSceneNodeFromName("cubeMesh1"); // Define the node to be cloned
var selectedNode = null; // Initialize a variable to store the selected node

function cloneNode(newName, position){
// Function to clone a node with a specified name and position
let clone = ccbCloneSceneNode(nodeForCloning); // Clone the specified node
ccbSetSceneNodeProperty(clone, "Name", newName); // Set the name of the cloned node
ccbSetSceneNodeProperty(clone, "Position", position); // Set the position of the cloned node
ccbSetSceneNodeParent(clone, parentNodeForClone); // Set the parent of the cloned node
}
function getSelectedNode(){
// Function to retrieve the selected node based on a raycast from the active camera to the mouse position
let rayStart = ccbGetSceneNodeProperty(ccbGetActiveCamera(), "PositionAbs"); // Get the position of the camera in the scene
let rayEnd = ccbGet3DPosFrom2DPos(ccbGetMousePosX(), ccbGetMousePosY()); // Get the 3D position of the mouse cursor
// Loop through each child node of the parent node for clones
for(child = 0; child < ccbGetSceneNodeChildCount(parentNodeForClone); ++child){
let currentChild = ccbGetChildSceneNode(parentNodeForClone, child); // Get the current child node
// Check if the ray intersects with the bounding box of the current child node
if(ccbDoesLineCollideWithBoundingBoxOfSceneNode(currentChild, rayStart.x,rayStart.y,rayStart.z, rayEnd.x,rayEnd.y,rayEnd.z)){
selectedNode = currentChild; // If intersection is detected, set the selected node to the current child node
break; // Exit the loop as the selected node has been found
}
}
}



new object
Guest
Quote
2024-03-29 14:51:04

So you can use the function 'cloneNode' to create a new clone and then call 'getSelectedNode' to retrieve one of these clones.


derty
Guest
Quote
2024-03-29 14:59:22

wow thanks ok but I know up to a certain point about javascript this works if I use the coppercube default function to click the cube which then does the javascript function where do I insert this? sorry and I'm trying to understand given my limited language


Create reply:


Posted by: (you are not logged in)


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