Jump to content

moving a camera forward using the code


Recommended Posts

Hiya T.  One way to move a camera... is with animation:


A rather fancy camera move... adjusting free camera position, y-axis pan, and x-axis tilt... with 2 Float-type and one Vector3-type animation.  Nice.

This PG demo is a modification of someone's fine demo... at http://www.babylonjs-playground.com/#24SBV7#6

It does similar, but it uses an arcRotate camera.

Here's another... freecam fly... using the render loop to power the camera flight.


Just a normal free cam, -340 units away from origin (line 5) and notice it is attached to the scene (line 6).  Yet the mouse won't pan or tilt this camera.  Why, you ask?

Line 31... I locked the "gizmo" box as the camera's target.  That's why.  The camera will still do some cursor up/down moving.  Not much.  :)

The camera moving... happens in line 53-55, where we use ONE way to "register" a before-render function.  Works gooood... but it keeps flying because it has no IF/THEN checker... to stop it somewhere.

Hey, look at lines 44-49!  ANOTHER way to register a before-render function.  I bet you can tell what THAT before-render function animates?  Yep, the wheel rotation and the box spinning in the middle.  Fun!  BOTH before-render functions are active at the same time.  Cool, eh?

Hey, I have an idea.  Let's "orbit" a target, and use the freeCam's lockedTarget to follow it around!


Works good!  What's that?  You want to leave the target in one place, and orbit the camera around the locked target (this time, a box)?  Ok!  Just some minor changes...  http://www.babylonjs-playground.com/#25A2AB#2

Now you have some fun freeCamera toys.  Hope this helps.  Party on!

Link to comment
Share on other sites

Hi again!

Notice that I said there were two float-type animations and one vector3-type animation?  http://www.babylonjs-playground.com/#24SBV7#16


I believe you were asking about animating all three position values at the same time (in another thread).

See line 19?  We set the animation to end at frame 10000, at new BABYLON.Vector3(-40, 25, 0)... a vector3.  Yay.  You could also use target.position, which is also a vector3.  But animating to a vector3 like new BABYLON.Vector3(-40, 25, 0) gives you more control of the stopping point.  Animating to target.position would probably put the camera right on top the target.  Might be ugly.  :) 

But, look at line 50, the animation starter.  It wants parameters for START and END frame number... so you could change that 10000 to 8000.  That way, you could set animate-to target.position, but then stop the camera move... at 80% complete (8000 frames). 

Neat, huh?  A way to fly 80% to target.position.  That way we don't break the camera ... from crashing into the target. ;)  Hope this helps.  bye again.

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.

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.


  • Recently Browsing   0 members

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