- Home /
How to have precise transform position for complex Blender Models with animations?
So I have just started experiencing this problem last night as we have upgraded our main character's .fbx model. So I have not had enough time yet to really try to figure out many solutions. But I wanted to just ask this question here from the start in case anyone already understands how this works.
Right now the player's movement logic as well as how enemies respond to the player is based off of the default transform.position of the previous model. For that model the transform position was centered in his chest and appeared to stay there no matter what animations or positions occurred.
I am now attempting to implement a new .fbx model which is much more complex than anything I have made myself, so I don't even really understand exactly how our artist made it (I believe they used the Rigify Add-on for Bipedal characters as well as most likely Inverse Kinematics).
The reason for some of the added complexity is to have features like swapping armor, so currently the armor the player is wearing can be repositioned separately from the characters actual body while in Blender. But it does appear as expected while in Unity. Could this have some kind of affect with this problem?
The problem is that the new models Transform position is not where it should be according to the Blender origin point. I have even gone into Blender and manually set the origin point to try to fix this.
The origin points appear to be below the character's feet? Is this caused by the Rigify Ad-don for Bipedal characters?
I don't understand how Unity calculates the .fbx objects transform.position?
With our old more simple model it seemed to automatically be set to the center of the models regardless of animations.
Is there certain kinds of animations or rig set ups that would cause Unity's transform.position to not stay centered in the characters chest? Is it possible that Unity calculates every single armature and cube and then bases the transform position at the center of all that?
This would cause the transform position to constantly be shifting to different areas relative to the player model based on the animation?
I could be completely wrong, but I am having trouble quickly finding any kind of helpful information about this in all of my searches so far. I figured that asking here would be a good idea if someone happens to have these answers :)
I am about to attempt a solution for this problem by creating a new empty object within the player model which will be used to give the accurate and consistent transform positions. However I am concerned that this position will not be accurate if it is based on the other problems I described above, it may itself not stay positioned as expected.
In my early testing of this new object, it already seems to have the capability to become off center even while having the IsKinematic box checked on the rigid body. Perhaps I need to create a completely empty object for this, as the current one is used for trigger events?
REALLY need any help with this, I have never encountered anything like this with all other .fbx models, I have NO CLUE what is going on or how Unity calculates Transform positions for something like this?
Please help!
Answer by Loius · Apr 08, 2013 at 12:03 AM
The mesh's center point is simply its center point. A mesh is always built relative to Origin, and Unity just applies a transform matrix to the mesh.
In the upper left of Unity there's a button that says either Pivot or Center; click it to swap to the other and see if that fixes what you're seeing.
In Pivot mode you see the object pivot, in Center mode it's the average position of all selected objects.
You can child your visual model to a control object (very common practice, separate graphics and logic).
Unity only gets polygons, bones, and animation from the FBX file; doesn't matter what was used to generate it (IK/FK, Rig Addons or whatevs).
Thank you for your quick response, I will try to investigate the Pivot vs Center for the character.
Yes I think the control object correctly set up should fix anything if I can't find a solution within the existing transform.
I just wanted to make sure there wasn't some crazy behavior that I don't understand that could be occurring. From your answer it sounds like that is not the case.
I did actually add one other enemy model that showed signs of these upco$$anonymous$$g problems.
The health bar over the enemies heads is based on their transform position. I am using something like this to get their position:
screenPosition = Camera.current.WorldToScreenPoint(transform.position);
screenPosition.y = Screen.height - (screenPosition.y + 1);
All the previous models worked correctly with this method. And then the most recent enemy model the health bar was off center to the left or the right, depending on which side the camera was.
I am going to investigate if using Pivot would fix this issue ins$$anonymous$$d of adding a new empty game object to that model. This health bar issue was part of the reason I thought the transforms may not always be in the middle of the model mesh.
O$$anonymous$$, while I still haven't had time to test the pivot vs center view for that one enemy with the health bar problem, I believe I have solved the problem for the main character!
I don't understand why this is working, but all I had to do was raise the transform.position.y coordinate for just one line of code. I just added a new vector to the models original transform.position to accomplish this.
The original problem and the new solution still confuses me a bit, as the current models transform.position.y height is almost identical to the old one. And according to the center position of the Transform in Scene View it is already significantly above the ground so I have no idea why raising it a little more has seemed to solve this problem.
Anyways thank you for your help, the main thing I wanted to know was whether transform positions could be affected by certain .fbx properties.
And although there is still some strange behavior and it seems I don't fully understand how my game is working right now in relation to the new models transform.position I think you were probably right with your answer :)
I will update this thread if I run into any more problems.
Hmm while positioning my player model in the Start menu I noticed something new.
The player's transform position while in Center View can shift based on the models rotation, at certain rotations it appears down by the feet ins$$anonymous$$d of in his midsection.... very strange indeed, and that would explain why the see$$anonymous$$gly random fix worked I guess?
Well, in Center view, Unity shows the average of all selected objects (or something... I don't really use that view very often). So as you rotate bits of an object it might seem like the over-object's center moves. Since it does.
I've never actually had occasion to use Center view, because I always want to know where my pivot is and I ... well, never care where the physical center of an object is.
Hmm this is good information thank you so much!
I was under the impression that the center view was the transform position? It does have the x,y,z vector position so I always assumed that must be the transform position?
But like I said I really have no idea how Unity works for these kinds of little details.
I have always found their documentation to be very vague and leaves me with so many questions I tend not even to use it that much because I never find what I am looking for :(
Generally I find much better information on the forums.
Answer by RyanZimmerman87 · Sep 13, 2013 at 11:37 PM
Just wanted to add that a lot of these problems with having inconsistent transform positions were caused simply by the .fbx settings in Blender. For example there are multiple different ways you can set the origin transform by pressing CTRL-ALC-SHIFT-C in Blender like:
Geometry to Origin
Origin to Geometry
Origin to 3D Cursor
Origin to Center of Mass
I recommend you find a consistent way of setting the transform positions through the .fbx for all your models to avoid the headaches I went through when I first started working with 2 different artists models that were very inconsistent in this regard.
The only thing I still don't fully understand about the .fbx files being imported from Blender are the bounding boxes in Unity. I'm not sure how they calculate these but they seem to be be very important in occlusion culling calculations and they often times have been extremely inaccurate in size and require manual adjustments.
Not sure if this is something my artist caused on certain models or Unity bugs.
Your answer
Follow this Question
Related Questions
Camera rotation around player while following. 6 Answers
Issue's With Positioning 0 Answers
An Efficient Way To Follow Transform's Position? 3 Answers