x


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.

more ▼

asked Dec 14 '11 at 07:54 PM

Sacrificer39 gravatar image

Sacrificer39
16 1 1 2

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.

Dec 14 '11 at 08:14 PM fafase
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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."

more ▼

answered Dec 14 '11 at 10:39 PM

Julien.Lynge gravatar image

Julien.Lynge
7.7k 20 25 52

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3124
x1285
x439
x427

asked: Dec 14 '11 at 07:54 PM

Seen: 956 times

Last Updated: Dec 14 '11 at 10:39 PM