- Home /
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:
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?
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.
I'm not entirely clear what you're asking, but...
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.
write other code that sets everything else, to be, how you want it to be.
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.