#Proper way of cloning gameobjects
1 messages · Page 1 of 1 (latest)
i have a method where i place a cube at that position where i want duplicated object and it works
so i guess theres some problem with duplication
show whats happening instead
cause passing position should work fine
unless the position was wrong
Instantiate literally clones an object
it justs stays on default position
i mean the original position where is the object which i want to clone
send current !code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
for (int x = -10; x <= 10; x++)
{
if (x != 0)
{
bool placeTree = false;
if (Math.Abs(x) > 5 && new System.Random().Next(3) == 0) placeTree = true;
if (placeTree)
{
string[] trees = {"Oak_Tree", "Poplar_Tree"};
GameObject tree = Instantiate(GameObject.Find(trees[new System.Random().Next(trees.Length)]));
tree.transform.position = new Vector3(prevoffset + x, 1.5f, -z);
tree.transform.rotation = Quaternion.identity;
}
}
}
so where is prevoffset and -z coming from
set those to 0 i am excited if it will work for you just on x axis
so you're only ever instantiating at 0 + i, in x?
I still don't see whats wrong
idk too that's why i am asking :D
can you show what is happening and where you want it instead
its hard to tell from here
make a vid , or screenshot with some lines
sure
hmm i figured out a better explanation
it sets the position as of now but it stays on origin position
but the position is set as i want
oh cause you werent updating it anywhere
so its solved?
and sorry, i didn't mean this rude
prevoffset = someValue
i mean the position of duplicated object is right
but it is displayed on origin position
wdym by that? maybe the pivots are whats wrong
the position of cloned object is right but it is displayed at the origin regardless setted position
the position of object that i am trying to duplicate
that makes no sense
I dont see that assigned anywhere to tell the clone to spawn there
well its like display bug or smth
hows it a bug if you havent assigned it anywhere
you assigned -10 to 10 on the x from the loop iterator
how that related to the object you want to clone