I am trying to put a sprite of sword within an empty game object so that way I can rotate the sprite about the hilt. But, for whatever reason, as soon as a I make my sword a child of the empty object, both their positions immediately become the exact same. It’s clear to see in this GIF I made of the issue. Why is this happening?
When you make the sword object a child of the empty game object:
Transform component starts using the local position of the empty object Instead of the world position.
So normal objects uses world position, child objects uses the local position of the parent object of itself.
When a child object uses the local position of the parent object, it’s position gets calculated related to parent object’s position. It assumes the parent object as the 0, 0, 0 origin and calculates child object’s position relative to that.
Let’s say there are 2 objects,
Object A’s position: 5, 0, 0
Object B’s position: 8, 0, 0
If we make the Object B a child of the Object A, let’s calculate what happens:
Object A’s position stays the same in world position: 5, 0, 0
Object B’s position becomes 3, 0, 0 because it assumes the 5, 0, 0 position as 0, 0, 0.
Either what @jackmw94 said, or it’s the animator is messing things up.
The animator component could modify transform positions (and rotations). I had a lot of weird things happening when I’ve been trying to figure out how to use animations and animator components in Unity. And this behavior looks pretty much like one of the issues I’ve encountered. Try to disable the animator and see what will happen then.
I was looking at your answer @Draxhtar as I had the same question. In a video I am Watching, Jason created an empty GameObject he titled Player. Then made the soldier to be a child of Player so should one want to switch out the characters, not having reset all the prefabs and etc. I also noticed the position of the parent and the soldier was not in the same exact spot.
Here is the part that throws me. In the video, Jason added Character Controller to the Player and not the child or soldier. The video showed the lines (similar to a collider, but it was actually on the soldier where when I followed suit it was not using the Parent that was renamed Player. Now when I removed the Character Controller from the Parent or Player and add it to the child or soldier, the lines like a collider does show on the soldier itself just like the video. Was that a mistake on the video itself???