Hello,
I am working on a script involving terrain generation and am creating new instances using clones from an original object. The problem is, I am viewing the Workspace to copy values, particularly the position and size into my script.
The original object in the Workspace, DirtBlock, is in the coordinates listed below for x, y, and z, respectively. it is exactly a 3 by 3 by 3 size block.
Here is the code [I would like to avoid]:
--the coordinates of the original DirtBlock x= -98.5 y= 2002 z= 98.5 clone= game.Workspace.DirtBlock:Clone() clone.Name= "DirtBlockClone" clone.Parent= game.Workspace clone.Position= Vector3.new(-101.5,2002,98.5) -- as you can see it is moved 3 studs in the x direction
My attempt is to use something like:
bob= game.Workspace.DirtBlock:getInformation()
and then print out the variable bob.
So, if i have the x, y, and z coordinates, I can do something, theoretically speaking, like this:
xNew= game.Workspace.DirtBlock.Position(x) yNew= game.Workspace.DirtBlock.Position(y) zNew= game.Workspace.DirtBlock.Position(z) clone.Position=Vector3.new(xNew,yNew,zNew)
Edit: I'm not sure how I will manage this, as I have tried approaches like creating instances from scratch with identically similar descendant properties.
It tends to be a good idea to group related information into a single value. Data structures like Vector3
let us do that.
Well designed objects let us do things to them without us tearing them apart and putting them together. For example, Vector3
let's us use +
:
local right = Vector3.new(0, 0, 3) local original = Vector3.new(-98.5, 2002, 98.5) local newPosition = original + right -- 3 studs in the z direction from `original`
RoboFrog, you mean as in :
print(game.Workspace.DirtBlock.Position.x)
?
Or,
testx= game.Workspace.DirtBlock.Position.x
and then substitute that in the Vector3 array for the x coordinate?