- Home /
Instantiate at a moving position
Hi guys. I've got a problem with my script. Im creating a VR welding simulation. In Unity I have a welding torch with which i can trigger the TriggerStay-fuction. I want the script to instantiate weald seams at the position of the GameObject "movableposition". This GameObject is a child of the welding torch, so the position of it is variable depending on the moving of the welding torch. I achieved that the weld seams got instantiated, but they all spawn on the same wrong position. Any suggestions to solve the problem? Thanks in advance!
Answer by banana111 · Nov 04, 2018 at 06:25 PM
First try this method: delete what you have in your void update and change your instantiating to : Clone = Instantiate(prefab, movableposition.transform.position, transform.rotation); you can call the object position when you want it. You don't need to change the position every frame. if this dosen't work try first Instantiating the object and then setting the Clones position to be equal to movableposition's position. But the best method would b using a particle system and setting the particle to be the object you want to instantiate. Since you are instantiating mannnny objects unity might lag and instantiate them at a wrong position that's why using unities in build partcle system might be better since it is optamized in ways you don't need to understand right now. I would recommend these two videos: https://www.youtube.com/watch?v=FEA1wTMJAR0
Thanks for the detailed response! The methods worked fine. I'll keep your suggestions for optimization in my $$anonymous$$d for the future :)
Your answer
Follow this Question
Related Questions
Checking if object intersects? 1 Answer
Removing instantiated objects?? 1 Answer
Instantiate Object At Local Position 2 Answers
Collider.bounds position is wrong? 3 Answers
How to Instantiate to Mouse Position 0 Answers