Jump to content

Is there a "Rotate To" function to rotate an arc camera?


JonVarner
 Share

Recommended Posts

Hey all, I have a use case where I have two camera positions, A and B. I am currently using an arc camera. What I would like to do is rotate the camera from position A to position B using the shortest path over a period of frames. I am confident I could code this but wanted to double check there wasn't already a built in function somewhere that I was unaware of? Just seems like it would be a pretty common task. Anyway, I just did want to invent the wheel if it was already available somewhere. :)

Link to comment
Share on other sites

Hi Guys!  I once did some mesh "spin" and "spinTo" funcs, and they work for arcCams too.

https://www.babylonjs-playground.com/#HH1U5#87

Lines 2-6 temporarily adds spinTo() onto this-scene-created arcCams.

Some demo calls are in lines 75-85.

I'm not a pro coder, so there could be tweaks needed.

I think there are 10 types of easing available in BJS.  I used CubicEase cuzzzz... it seemed to work nice.  :)

You might run into SOME issues... for camera.alpha... in regards to WHICH WAY TO SPIN to get to new target-alpha value.

Possibly, spinTo() needs a 4th parameter, a "positive" or "negative" to indicate which direction to rotate to new target.

Sorry if I ruined the adventure-fun of writing an arcCam spinTo() animator.  :)

Note:  Internet Explorer may dislike the ()=> usage in lines 75-85 demo calls
If problems in IE occur, use this format:   setTimeout(function(){camera.spinTo("beta", 1.2, 20), 1000});

Link to comment
Share on other sites

I think... you can also use your CURRENT SpinTo animator... to animate the camera.target.  Just change the whichProp to 'target'.

An ArcCam target is a vector3 value (like invisibleMesh.position).  An ArcCam lockedTarget is EITHER a mesh or a vector3.

Animating arcCam targets and lockedTargets... is often used for "click on mesh to make cam look at clicked mesh".

When user clicks a mesh, you can animate camera.target to clickedMesh.position.  It's not really a "spinTo" in the classic sense, but it still works.  It's more like moveTo(), eh?  *nod*

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...