Parenting camera to object but keeping rotation?

Hi,

I’m having trouble with changing parents at run-time. I have an object that is rotating slowly and when the camera approaches the object, I make the camera a child of the object. I do this because I want it’s rotation and position to follow the object’s movements. I would use a script to just update the camera’s position, but the camera is user-controlled and I want the user to be able to move around the object after being parented.

At the moment I parent the camera, though, it’s rotation snaps to match that of the object. I don’t want that behavior - I want the camera to have the same global rotation that it had before being parented.

I’m thinking right after I parent the camera I have to figure out the difference of it’s pre and post parenting rotation and set it to that, but I can’t figure out what methods to call on the camera - I’m a bit new to local/world space issues.

Any help is much appreciated!

fortunately it’s easy!

in game engines you constantly have empty objects, that are either wrappers or markers.

example, say you have an “enemy”. you might have a wrapper for sliding motion, and a wrapper for rotational motion, and yet another one for something else, and so on.

in short make a new empty object and call it SuperThing. Now sit your current object inside that, we’ll call it Thing.

now all your rotation and so on, do that on Thing, nothing will change. (just change all your current connections carefully)

now . parent the camera NOT TO “Thing”, but rather to SuperThing.

this is the heart of game engines, everything is ridiculously easy - you’ll be amazed how simple. Hope it helps