Topic: Code Snippets.
I want to post a collection of code snippets that do useful things you could use in your game. I will try to keep the code short and easy to understand;
Clone an object on another object's location:
function offsetClone(object1,offset,object2)
if onKeyUp("M") then
objectPosition = getPosition(object2)
clonedObject = getClone(object1)
setPosition(clonedObject,{objectPosition[1] ,objectPosition[2] + offset,objectPosition[3]})
end
end
How it works:
This function takes three arguments:
-The object whose location you want to use
-The direction along the Y axis you want to offset the clone
-The object you want to clone
Usage:
function onSceneUpdate()
offsetClone(clone,3,object)
end
It can be read:
Offset the clone object three units from another object (along the Y axis)
More functionality:
function offsetClone(object1,offset,object2,axis)
if onKeyUp("M") then
objectPosition = getPosition(object2)
clonedObject = getClone(object1)
x_axis = {objectPosition[1] + offset,objectPosition[2],objectPosition[3]}
y_axis = {objectPosition[1] ,objectPosition[2] + offset,objectPosition[3]}
z_axis = {objectPosition[1] ,objectPosition[2],objectPosition[3] + offset}
setPosition(clonedObject,axis)
end
end
offsetClone(clone,.5,object,x_axis)
It can be read:
Offset the clone object .5 units from another object along the X axis
Last edited by Tutorial Doctor (2014-01-30 01:02:50)