x


Preventing parts of a prefab from rotating w/parent?

I'm sort of new to creating complex prefabs, and am having a couple of issues that I think are just a result of my inexperience. My prefab is made up of three parts:

  • Turret Top
  • Base for the Turret
  • Dummy Node (used as instantiate point for projectiles)

The "Turret Top" object carries a script which handles rotating itself to track the mouse, firing projectiles, and attaching the dummy Node to itself. It is also the top-level of the prefab. The other two items show up beneath it in the Project view. TBH, I'm not really sure what the significance of hierarchy is here (and probably should).

There are two issues I'd like to solve:

  1. When I instantiate this prefab, it uses the pivot of the Turret Top object for placement. I'd prefer to use the pivot of the Turret Base. Is there a way to do this? Should I just re-build the prefab with this as the top-level item, or does that carry other ramifications?
  2. When my Turret Top is rotating to track the mouse, the Turret Base is moving with it. Can I tell my prefab not to do that? I just need the Base there visually, and when I create my "real" art I'd much rather just build two meshes and rotate one completely, as opposed to having to create an actual animated object.
more ▼

asked Jun 09 '12 at 05:39 AM

nongenre gravatar image

nongenre
42 5 9 11

I'm not entirely clear what you're asking, but...

  1. write some code that sets the turretTop to be, however you want it. You may well use things like "LookAt" to make it look at some distant mountain or marker point.

  2. write other code that sets everything else, to be, how you want it to be.

  3. when you instantiate the object. run the code mentioned in 1 and 2. (ie, very likely in "Awake()" or "Start()" .. or something like that ... or called from the thing that instantiated it.

in this way the things mentioned in 1 and 2 will be done to your stuff. and everything will be how you want!

PS a handy tip I have found when getting started. Just FORGET about prefabs. Have one of your tanks/whatever simply SITTING OFFSCREEN. then, instantiate it as a new one. and position it, and so on, and run the code mentioned in 1 and 2.

i just find that easier somehow than worrying about prefabs.

Jun 09 '12 at 08:18 AM Fattie
(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
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:

x2164
x1672
x1255
x224

asked: Jun 09 '12 at 05:39 AM

Seen: 344 times

Last Updated: Jun 09 '12 at 08:18 AM