How do I find the lookAt vector for this problem? (Image illustrated but mathematically hard)


I got this problem. My character (the box) walks on a sphere. My camera is looking at him, but he needs to look away from the camera yet still have his foot on the ground.

I need to findout the green arrow. The yellow is the camera direction from it’s location.

The blue vector is also knows, it’s simply the position of the character because the spheres center is at (0,0,0).

Here are some more examples:

But the camera can also be at any “height” like in these images:

I am really perplexed when it comes to this…

I am most grateful for all hints because this is really essential for my game progress.

Take the blue line as your axis. Project a line at right angles from that one to your camera.

The green line will be the normalized inverse of that.

Yes, that’s what I’m trying to do…

I manage to make a vector from the cam location to the character location.

But to “angle” it down so that it’s linear with the red plane is hard. Dunno how to do that :frowning:

Simplest way:

side = yellow.cross(blue);

green = side.cross(blue);

The cross product is order specific so I may have one or both of those flipped.


That actually works! :smiley: Thanks alot man!!!

Works like a charm :smiley:

1 Like

cross products and inverse transforms really are magic

1 Like

You can pretty much conquer the world with a good understanding of dot products and cross products.

After all… even a rotation matrix transform is just three dot products.

1 Like