GetClone

(Difference between revisions)
Jump to: navigation, search
(Created page with "Get an object clone object = getObject("object") objectClone = getClone(object)")
 
Line 1: Line 1:
Get an object clone
+
Clone an object.
 +
 
 +
#''Some notes about clones :''
 +
#* They keeps the base object active behavior
 +
#* They keeps physics proprieties
 +
#* They don't keep the translate/force/etc.. values of the base object from lua script (because they are new objects)
 +
 
 +
Basic usage :
  
 
     object = getObject("object")
 
     object = getObject("object")
 
     objectClone = getClone(object)
 
     objectClone = getClone(object)
 +
 +
For referencing you can store them into a table :
 +
 +
    object = getObject("object")
 +
    cloneList = {}
 +
    function onSceneUpdate()
 +
            if onKeyDown("SPACE") then
 +
                table.insert(cloneList, #cloneList + 1, getClone(object)) ''-- create a clone''
 +
            end
 +
    end
 +
 +
With that method, the first clone will be cloneList[1], second clone will be cloneList[2], and so on..
 +
 +
To manage all these clones at once you could add to the script, for example :
 +
 +
    for i=0, #cloneList do
 +
        rotate(cloneList[i], {0, 0, 1}, 1, "local")
 +
    end
 +
 +
In this case all the clones currently on the scene and the newly created ones will rotate.

Revision as of 09:53, 4 November 2012

Clone an object.

  1. Some notes about clones :
    • They keeps the base object active behavior
    • They keeps physics proprieties
    • They don't keep the translate/force/etc.. values of the base object from lua script (because they are new objects)

Basic usage :

   object = getObject("object")
   objectClone = getClone(object)

For referencing you can store them into a table :

   object = getObject("object")
   cloneList = {}
   function onSceneUpdate()
           if onKeyDown("SPACE") then
               table.insert(cloneList, #cloneList + 1, getClone(object)) -- create a clone
           end
   end

With that method, the first clone will be cloneList[1], second clone will be cloneList[2], and so on..

To manage all these clones at once you could add to the script, for example :

   for i=0, #cloneList do 
       rotate(cloneList[i], {0, 0, 1}, 1, "local")
   end 

In this case all the clones currently on the scene and the newly created ones will rotate.

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox