- Home /
Unity 2D : How to make a perfect clone of my Game Object?
Hello I have a gameobject rock in my game scene and I cloned it and made it appear in the same position after it exits the game scene by using OnBecameInvisible but the problem I am facing is that after it re-appears it's actually a bit faster and just like that a bit more faster in the next turn and it keeps increasing. I tried using delta time but after using this the Rock doesn't even re-appears I have 2 rocks coming from both side of screen and hitting the ground and exiting the game scene, but I want my gameobject (rocks) to follow the same path and speed just like in the initial run but it changes right after they re-appears and keep changing one of the rocks even disappear after 3-4 runs(w/o delta time)
Please help me with the script I am new to unity.. Thanks everyone
In the picture that I attached is how the initial run goes but after that it just changes and I want it to keep following the same path, should I not clone and do prefab ? If yes please help me with prefab script so that my object pooling is just like the original one. Thanks a lot
This is most likely a scripting issue and not a prefab/object issue. Please provide your code so we can see what is going on. And you say there is a picture provided but.. well there isn't :P
i am sorry, i am unable to upload the picture i am getting "Error parsing the uploaded file"
Check now, i have added pics and vids of game scene and script
Answer by rufopufo · Jun 27, 2019 at 11:15 AM
Hi there,
It seems like that rock is saving the speed that it has when it exits the scene. So when you clone, you start with that speed instead of starting without any speed.
To avoid this, and believing that the rock has a Rigidbody attached to it, you have to set its velocity to 0 when it exits the scene.
yourRock.GetComponent<Rigidbody2D>().velocity = Vector2.zero;
If your rock does not have any rigidbody attached to it... We will need some more information about your scene and components.
Hope it helps.
https://drive.google.com/open?id=1-2l8DEVaTOmiPVT1sI9vX79VkQz1QxlJ <<< This is the game scene and how the rocks move in the initial run
https://drive.google.com/open?id=1i$$anonymous$$2Hz8b5HTpERiGrtl$$anonymous$$xGmpvkwpqhd1x <<< this is my script, i also added your code but its still not working, the rocks are going crazy. i have rigidbody attached to the rocks
https://drive.google.com/open?id=1yxm0Vm$$anonymous$$wyFs$$anonymous$$p$$anonymous$$d0GB00aOFzwqI$$anonymous$$FxdI << this is the initial run and i want the rocks to keep following the very first movement they have but right from the second run they are going crazy and sometimes the right rock doesnt even appear https://drive.google.com/file/d/14tTGJnN1c2eyYYb1kwP7xVuphuI9sd5V/view
please help me with the script
Also, lots and lots of thank you for helping me( im sorry but dont $$anonymous$$d me cos i might say "thanks" a lot of times, i just like to appreciate the help that one is giving :D )
i hope you can se the vids and pics
I believe that the error is not on that script. The problem is generated when you clone, or reposition your rock. Sorry but i can't help any more :(
well thanks a lot for even trying okay, Hope someone else can help but thanks anyway :D
Answer by KimMingyuSVT · Jun 28, 2019 at 10:10 AM
i also have a new physics material 2D for bounciness.
Answer by KimMingyuSVT · Jun 28, 2019 at 10:55 AM
Hey there, @Bunny83 @thor348k @Eric5h5 @crazyKnight @SirCrazyNugget can anyone help me with this? i am abit new i hope someone can help me, Thanks! :D
Your answer
Follow this Question
Related Questions
How to obtain this prefab name in this circunstances 1 Answer
Instantiated clones arent behaving the same as the prefab 1 Answer
Getting an error even if the script works. 1 Answer
Script on prefab keeps values from one execution to another 1 Answer
How do I make a clone of a prefab appear on the correct layer? [5.2.2f1] 1 Answer