0 votes

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 lookat and Lookatfromposition. 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)?

in Engine by (510 points)

1 Answer

+1 vote

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.

by (572 points)

Thank you. And yes, lookatfrom_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 getparenttransform 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.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.