x


How can I easily dynamically move a stack of gameobjects?

I'd like to move a stack of gameobjects - like a pile of bricks - intuitively and quickly in code. I've already got the pile of gameobjects in the world and would ideally like to transfer them around whilst staying piled together as they currently are.

I'm wondering if perhaps i could do the following

  • have a carrying empty gameobject
  • position carrying gameobject at the centre bottom of the pile in the world
  • add each gameobject brick as children to the gameobject
    • it's crucial that in doing this the gameobject will stay in exactly the same world position
    • yet i guess their actual positions that are now relative to the carrying game object will need to be altered into the correct space?
    • once all gameobjects are added i can then simply translate the carrying game object around to move the pile of objects
    • after placing where desired I can then move each of the gameobjects out of the carrying gameobject hierarchy and back into the world root (or another suitable gameobject hierarchy)
    • if any space transformations were needed putting them into the carrying gameobject then i guess they'll need to be reversed here
    • the carrying gameobject can be left till its services are required again

It all sounds relatively straight forward, i guess the crux is

  • can you dynamically create hierarchies of gameobjects at runtime?
  • are space transformations required when objects are moved into and out of new hierarchies?
  • what members and functions are required to accomplish this?

Cheers

more ▼

asked Dec 29 '09 at 02:31 AM

jimbobuk gravatar image

jimbobuk
1.1k 34 42 54

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

you can do this easily. you just need to set the transform.parent of each block to your parent gameobject and then set it back to null. there is no need to space transformations. go ahead and use great easy to use powerful unity!

more ▼

answered Dec 29 '09 at 07:40 AM

Ashkan_gc gravatar image

Ashkan_gc
9.1k 33 56 117

cheers.. So long as the carrying gameobject was positioned where i wanted it relative to the future children then yes it was very straightforward.. Joy! :)

Dec 30 '09 at 12:34 AM jimbobuk
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5081
x2087

asked: Dec 29 '09 at 02:31 AM

Seen: 1695 times

Last Updated: Dec 29 '09 at 02:31 AM