- Home /
How to not let Child object rotate with Parent
Hi!
How do I make a child object move along with the parent object, but don't let rotate?
I ask this question specificly for the Cube / Mobile skybox. When the cube is a child of the camera, it obviously moves along with it, but it shouldn't rotate..
Anyone got an idea?
Thanks in advance!!
I made this script, but it's real jerky, and I can't believe there isn't an easier way :D Thoughts?
function Update () {
var Camera = GameObject.Find("$$anonymous$$ain Camera");
transform.position=Camera.transform.position;}
Don't use GameObject.Find to grab the main camera. It's already easily and quickly available in Camera.main.
You really, really shouldn't use a classname as variable name. "Camera" is a class, when you call your variable the same you can get in trouble.
Answer by Waz · Aug 03, 2011 at 09:53 PM
Do as per your comment, but after you move the camera (eg. in LateUpdate) to prevent jerking:
function LateUpdate()
{
transform.position = Camera.main.position;
}
Of course, if for some reason you are changing the camera position in LateUpdate
(scripts often do this in order so that the camera tracks the latest position of, say, the player), then you'll need to modify call order. IIRC, OnPreCull
is called after LateUpdate
, so you could use that too.
Alternatively, just do the work in your camera positioning script:
...
transform.position = ...
skybox.position = transform.position;
Thanks! But could you clarify a bit? Ins$$anonymous$$d of Function Update I should use LateUpdate? The script itself is by the way a big strain for the mobile phone. Can't the same effect be reached by editing the shader, and if so, will that run faster or slower?
Yes, doing GameObject.Find
every frame is not a good idea, mobile or otherwise.
So, is it correct then that the mobile skybox does rotate with the camera, and therefor doesn't rotate on screen? In essence it's just a cube with a shader on it, and how you move it is up to us? Thanks though for the answers guys!
Actually: It should be:
So
function LateUpdate()
{
transform.position = Camera.main.transform.position;
}
It is still Very shakey, but that may be due to the camera script. I'll test it out tonight!
Your answer
![](https://koobas.hobune.stream/wayback/20220612165659im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Why are the default Skyboxes really low quality on mobile (iOS)? 2 Answers
Make a simple tree 1 Answer
How to Create Cube Skybox Texture 2 Answers
How can I hide HDRI skybox view from my game view but still get its lighting features in realtime? 1 Answer
How to made a normal skybox with a rectangle part of solid color 0 Answers