FollowCamera vs Mesh.LookAt (does not work together)

I use both FollowCamera and Mesh.LookAt.
But it doesn’t work together.
When LookAt works good then the FollowCamera looks on my hero from front. But I want the FollowCamera to follow my hero from behind. The only way for this I found was to redraw the hero - swap his front and his back.
But now my hero (when I use Mesh.LookAt) looks at a point by his back. And I want him to look at the point by his front.
The only workaround I found was that I calculate the flipped (opposite) point of point which I want to look at. But this is not very nice.
Can anybody help?
Thanks.

Welcome to the community !!!

The easiest would be to create a playground so that the community can help having a stab at the issue ?

Hi, ok, I created a playground for this problem: https://playground.babylonjs.com/#7J251R#1
Click on any ball to raise a lookAt action.

The FollowCamera looks on front of my hero (which is bad, I want to look on his back). I can redraw my hero, so his front will be on the back and vise-versa. But then when I want him to look to any object, he will show his back to this object. I found a workaround: I created my own “lookAt” method, which first calculates the point on the opposite side from the hero of the point I want to look at. But this looks a bit ugly to me.

It seems to me like a bug, because you usually want to look on a character’s back and not his front. At least there must be an option to swap it. Or is it there but I missed it?

Thanks.

Hi @Michal_Mihalik and welcome to the forum from me. You can rotate your ‘hero’ and bake the transformation into the vertices as in https://playground.babylonjs.com/#7J251R#2

Hi, John.

Thank you for your suggestion but this is not working as I wrote upper.
Just try to click on any of the ball in your example. The hero is “looking” on the ball by his back.
Again, I need the camera to look on hero’s back and also I need the hero to look on any elements by his front.
Simple rotation will not work as it will brake the proper “lookAt” behavior.

But what really work is workarround of lookAt like this:
//dude.lookAt(pickInfo.pickedMesh.position);
var invertX = 2 * dude.position.x - pickInfo.pickedMesh.position.x;
var invertZ = 2 * dude.position.z - pickInfo.pickedMesh.position.z;
dude.lookAt(new BABYLON.Vector3(invertX, pickInfo.pickedMesh.position.y, invertZ));
Try the example here:
https://playground.babylonjs.com/#7J251R#3

This solution works but I don’t see it very nice as I cannot use “lookAt” directly but I need to call a workaround method instead of it.

OK get it now. You click on blue sphere, Dude looks at blue sphere and your view is from behind Dude looking over his shoulder at the blue ball in the distance.
Does it have to be a follow camera? Could you just make an universal camera a child of your hero. A couple of examples
https://www.babylonjs-playground.com/#102TBD#31
https://www.babylonjs-playground.com/#SQFG0Q#6

It does seem a bit weird that follow camera faces the forward vector of a mesh. As a workaround, you can negate the radius of the follow camera. The math happens to work out.

https://playground.babylonjs.com/#7J251R#4

2 Likes

Thank you, bghgary. Your workaround is much more elegant than mine.

1 Like