Orbitcamera: Camera Focus Distance and smooth movement

Hi, somehow I’m not able to focus my objects perfectly with the oribitcamera script at runtime.
It focuses my objects on startup, but after changing the geometrie (with bones) I’m unable to focus the entity again so that it fits to the window size. I’m calling the OrbitCamera.prototype.focus to update the focus but it doesn’t fit.
The camera is too far away and I just wonder why.

Before that I’ve tried OrbitCamera.prototype.resetAndLookAtEntity but then it looks from a fixed reset point which is also not what I want.
What I really want it the function from the PlayCanvas Editor here ^^

focus

If you know what distance to set the camera from the entity, that can be used instead to ‘focus’ on the entity.

The math could use some tweaking in OrbitCamera.prototype.focus as I think it may be overly safe?

1 Like

Yeah, if you don’t want to edit the min and max distances in the editor, you can always just manually set the this.distance value in the OrbitCamera script. Probably something to do with the bounding box for that model or the entity you’re containing the model in. Might need to play with OrbitCamera.prototype._buildAabb which works with .focus() as @yaustar mentioned.

2 Likes

Hi,
thanks for your support.
I’ve written two functions smoothFocus and lookAndFocusAtHotspot and added it to the orbitcamera.js

smoothFocus: smoothly change distance to look at whole entity with children
lookAndFocusAtHotspot: smoothly change distance, rotation and position (optional) to look at whole entity with children

FionNoir/PlayCanvasLib: (github.com)

I’m sure this can be done cleaner and easier. But I didn’t understand the tween.js lib and was looking for a quick solution.

2 Likes