Limiting the mobility of `followCamera` using a latitudinal axis angle

Hello everyone :wave:

My goal is to track an instanced glTF model using the followCamera class, while keeping the camera above a specified latitudinal axis angle. Essentially, I would like to set an upper value for beta:

Screenshot from 2022-07-29 15-03-05

From my understanding, BABYLON.FollowCamera does not provide the ability to keep the camera above the ground (using the latitudinal axis angle). More specifically, BABYLON.FollowCamera does not have a property, accessor, or method that enables users to define a upper beta limit, which specified the maximum allowed angle on the latitudinal axis.

BABYLON.ArcRotateCamera includes the member upperBetaLimit, which meets the needs of my use case, yet does not include various other methods (camera acceleration and rotation offset) which I consider to be more important.

Any suggestions? Is there a reason why BABYLON.FollowCamera does not have the member upperBetaLimit? Are there plans to add upperBetaLimit to BABYLON.FollowCamera in the near future?

-Sam

Hi @srothst1 and welcome to the community. Weekends can be a little slow so I have given you a bump up.

The follow camera does not have a beta property since it is based on a free camera. It does have

which may help.

There is also a

which has a beta property but no restraints on it as far as I can tell, except that it will remain at what you first set it.

Just to double check, you are after a camera that follows a mesh automatically with no user input?

Otherwise you can do something like this

from

and you could limit beta.

3 Likes

Hi @JohnK. Thank you for your timely response.

The two followCamera properties that you mentioned (lowerHeightOffsetLimit and upperHeightOffsetLimit) are helpful. While they may not meet my exact needs, they should be serviceable for the near future.

Yes, I am looking for a camera that automatically follow a mesh :+1:

The Babylon.js Playground project that you sent over was great! For future reference, I put together a modified demo that showcases how lowerHeightOffsetLimit and upperHeightOffsetLimit can be used to limit the vertical offset angle of the camera: https://playground.babylonjs.com/#KBS9I5#25315

-Sam

2 Likes

Hi @JohnK and the rest of the community.

I have a follow up question regarding the followCamera class.

I would like to use a mouse drag to manually update the value of followCamera.lockedTarget relative to the original target. Thus, as the value of the original mesh moves (dude in the demo shared above), followCamera.lockedTarget should be updated accordingly.

Please let me know if you have any suggestions.

@PolygonalSun might have some ideas ?

Some additional notes:

The FollowCamera class has the property lockedTarget. This property defines the target of the camera. However, it also disables camera panning. I would like to define the target of the FollowCamera class while enabling camera panning.

AFAIK, there isn’t anything out of the box that could create the panning functionality with the FollowCamera but the ArcRotateCamera does have a property called targetScreenOffset which will shift the camera’s center by some x and y, with respect to the screen. Other than that, I suspect that either a custom camera input might be required for this functionality. Either that or add to the ArcRotateCamera’s functionality to move similarly to the FollowCamera.

Hi @PolygonalSun :wave: Thank you for the timely response. I wanted to share some updates with the community.

I created a demo implementation that leverages ArcRotateCamera.targetScreenOffset to update the panning of the camera as well as scene.pick(scene.pointerX, scene.pointerY) to determine picked positions in the scene. Sadly, the functionality of this implementation is not amazing, especially in a larger demo with a moving mesh.

Next, I considered a two mesh approach that uses the FollowCamera as well as the Mesh position property. An invisible mesh is added as a child of the visible mesh that I wish to track with the FollowCamera. FollowCamera.lockedTarget is set to the invisible child mesh, which initially has an offset of (0,0,0) from the parent mesh. The position of the invisible child mesh is updated according to the magnitude of the users mouse drag. Please note:

  • The position of the invisible child mesh is always set relative to the visible parent mesh.
  • The following function is used to dampen the volatile mouse drag input: F(vector_length) = 10 * Math.atan(0.125 * vector_length).

Here is the demo of this method with a moving mesh. Please keep in mind that this is still a work in progress.