- Home /
How can I prevent position of a child transform to be hooked to the parent in a prefab?
Basically, I am working on a networking project with a top down view.
I have a prefab player object with all of my scripts attached.
The problem is, I have a code that I have made for the camera to follow the player, but since it is network code, I am trying to get the camera to spawn with the player prefab, but not take the position of the parent.
Things I have tried/attempted:
Having the camera in the scene rather than spawning.
Spawning a separate camera prefab.
Different ways to spawn the separate camera prefab..
Also, when I had it spawned separate, it was not correctly finding my player.
Things I will try after posting and keep updated:
I am going to try changing my cameras follow code rather than the camera finding the target, I will have the target find the camera.
Also, any other information on networking cameras would be greatly appreciated, thank you.
Next to the rotation, scale, position and hand in the left corner you have a button local global. I think it switches between the two, so that the object position is in the global world or the local world (parent world).
If I am wrong i will remove that comments.
Answer by Julien-Lynge · Dec 14, 2011 at 10:39 PM
I'm not sure I quite understand what you're doing, but your basic question "How can I prevent position of a child transform to be hooked to the parent in a prefab?" is easy to answer. A child transform is entirely relative to its parent - its position is relative to the parent position, its rotation is relative to the parent rotation, and its scale is relative to the parent scale. There is no way to 'uncouple' a child from its parent other than to remove the parent/child relationship. You can't do that within a prefab - you have to do it after the prefab is instantiated in scene. Here's how you uncouple a parent/child prefab:
Instantiate the prefab.
On the child, set 'transform.parent = null;' The child is no uncoupled - it has no parent.
Then, set the 'transform.position' to wherever you want it to be.
Just FYI, transforms and parenting have nothing to do with networking (I assume that by networking you mean "sending information over a network."
I would downvote this if i could. This doesn't provide a solution as to how to reposition the child back to the position it would be if it were still attached to the parent.