How to make camera look at/track to a rigid body but ignore its orientation???

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Macryc

Hi All.

I have a scene in which a rigid body falls out of a plane then hits a mountain slope and starts tumbling down colliding with all sorts of obstacles on its way down. There’s a lot of bouncing, sudden rotations etc.

I want to create a camera that will follow said object as it tumbles down the mountain.

I’ve tried the interpolated camera, I tried look_at and Look_at_from_position. They all kinda work but each time the object runs into an obstacle and starts spinning the camera goes crazy (it shakes and/or orbits uncontrollably in reaction to its target’s sudden orientation changes).

Is there a way to make the camera completely ignore the orientation of its target that is a rigid body, and instead just “look in its general direction” irrespective of what happens to it (similar to what a ‘track to’ modifier would do in Blender or Maya)?

:bust_in_silhouette: Reply From: tastyshrimp

I’m pretty sure the look at does exactly what you described, from the docs, it looks at a Vector3 coordinates in space there is no rotation included in the description or parameters.

On the other hand, what you describe seems to be that your camera is a child of your RigidBody, like most tutorials show because that makes following really easy, basically free. But that also means that the Camera itself is being moved and rotated in accordance to it’s parent, a child node local space is based on the parent, so when the RigidBody moves and that includes the body rotation the camera moves and rotates with.

As such, you should think about making the camera a sibling of the RigidBody and move it in accordance to the RigidBody transform minus rotation. Or clean up the parent rotation every frame from the camera base.

Thank you. And yes, look_at_from_position actually does exactly what I want - the problem was I messed up the hierarchy.

Yes the camera is a child of the tumbler. In the camera’s script I used get_parent_transform to capture the tumbler’s origin and make it a target for look_at.

What I forgot about was that sometime in the process of experimenting with this I added a target node between the tumbler rigid body and the camera (hence making the camera a child of the target, not the rigid body directly). This would work fine too, except I must have accidentally moved the target away from the pivot point of the tumbler at some point. The poor camera was trying to catch up with the target node as it was orbiting like mad around the tumbler. Hence the shake.

Anyway, solved. Merry Xmas.

Macryc | 2019-12-24 06:57