I’m scripting some turret functionality in to my game. These turrets are attached to my ship.
The big problem though is the models I have created to be used! They never orient or scale correctly after being imported from Blender3d. I have a turret “Base” object which rotates the gun, and a “Gunbarrel” object which is a child of the aforementioned base object. Its easy enough to make them point at the target (I think) yet when I’m testing the game they are not oriented correctly. I attempted the unity documentation fix for making assets face the right way; by placing empty game objects. That kind of worked but not for the child object. I even tried placing another empty child game object between the parent “Base” object and the child “Gun barrel” object.
I can only say I’m super frustrated about this.
This is a picture of my hierarchy for the turret prefab:
The scale of the gun barrel objects is not correct either… Either I make it a scale of 1 and have it be massive on camera, or scale it down and deal with positioning issues. What am I doing wrong? Is there a better way?
I’m unsure of what else to take a picture of to help you understand whats happening. If you think of anything let me know and I will oblige to provide it…
I’m probably gonna take a lot of flak for it but I just solved the problem. It boiled down to local positions/child position offsets and a specific line in my script which controls the guns behavior. What I managed to do was make sure my actual game objects, my assets were at zero for every position value on both the “base” and “gunbarrel” objects (called the “TurretBase” and “Gun” objects in my picture above just in case it wasn’t clear). This put the empty game objects above them which controlled their actual positions in the exact same place as the game object. Then it was a matter of putting those empty game objects (the “parents” in the picture) where I needed them!
Sorry if I just wasted someone’s time reading this; I spent three hours straight on this problem and its related problems today. I didn’t just find myself frustrated then hit the forums in search of someone to fix it for me!
It’s usually best to make sure your meshes import at their proper scale and orientation rather than messing with scale on every single prefab. Here’s the documentation (Unity - Manual: Model tab), note the “Scale Factor”. Just play around with that until it matches your in game unit scale.
As for orientation, positive Z is forward, positive X is right and positive Y is up
1 Like