Spring physics powered 3D camera for Away3D and Papervision

Spring powered 3D camera demo

When building flash 3D application it is often necessary to implement complex routines to manage camera movements. Wether it’s a 3rd person follow cam, a first person FPS camera or a more customized movements most of the time it would be desirable for developers to have access to a simple camera that implements a “natural” movement.

While developing a small racing game internally as a pet project, I came across the need to develop such a camera, one that would allow us to easily tail a moving object in the scene while keeping the right orientation in relation to the subject. Though, that is simple to do by itself, what really makes this camera interesting is that it’s not a “perfect” follow. In order to give a good acceleration effect on turns and in “turbo boost” moments, I wanted a camera that would be a bit late in it’s follow and allow for smooth and more natural feel, something that you see in classic 3D racing games.

Hence the Spring Camera was born, a camera that works very simply by implementing spring physics between the camera and it’s target. Imagine the camera is linked by a spring to a target, when the target moves in 3D space the spring extends and then “pulls” the camera thus giving a nice natural feel to the movement.

“One camera to rule them all”

Here is a sample Away3D code to initialize a spring cam in the View. By default, the spring motion is activated once the target property of the camera is set:

Ovbiously, there are more options. 3 main parameters are used to control the behavior of the camera:

Mass - The “weight” of the camera, how difficult it is to pull it.
Stiffness - How hard the spring is to extend. A high value here is as if the spring was a stick (or fixed lenght)
Damping - Controls how the spring resists the spring “boingggg” effect. A higher value makes for a smoother ride, lower values and the more boing you’ll get.

The camera also implements 2 important offset:

Position offset - Where the camera should be ideally in relation to the target (in model space). For example, if we want the camera to try to be 100 units behind the target, we’ll use a value of Number3D(0,0,-100); Obviously if the target moves fast we won’t stay 100 units behind exactly which is how the effect is created.

Look offset - Where the camera should look at in relation to the target. By default, the camera look AT the target but you might want to have the camera attempt to look at a different spot. For example, Number3D(-100,0,0) would look 100 units to the left of the target. (all this in target model space).

And that’s pretty much all there is to it in terms of usage! The camera will automatically set it’s position in relation to the target based on the physics of the spring every frame without any additional code. Now all you need to do is move the target in 3d space and change it’s orientation…the camera will automatically follow.

All of these parameters, including target can be modified at runtime and will be updated real-time so you can do some pretty funky adjustments in your application code to create specific effect when needed.

This camera can be used to build a wide variety of cool cameras movements including but not limited to 3rd person camera, 1st person camera, chase cam, as well as all the standard camera parameters. You can even use it for cool transition effects!

Take a look at the Spring physics powered 3D camera demonstration.

Download the SpringCam class for Away3D.
Simply add the class in your Away3D source in the src/away3d/cameras folder.

Download the SpringCamera3D class for Papervision3D.
Simply add the class in your PV3D source in the src/org/papervision3d/cameras folder.

You can also grab the source code to the demonstration (away3d 2.2.1+ required)

Special thanks go to Kim Reeves for giving me a needed hand in whipping up the demo. Kudos!

UPDATE: John Lindquist created a short example using the original Focus example for pv3d with source available.

Hey if you like it or use it in a project, let us know with a comment and subscribe to our RSS feed!

11 Responses to “Spring physics powered 3D camera for Away3D and Papervision”

  1. Eric Poirier Says:

    As if I’m not biased.

    This ROCKS.

  2. NateJC Says:

    Very handy, thanks.

  3. pedzouille Says:

    very nice !!! bravo dieu !!! toujours aussi fort !!! lol
    à quand ce bel effet sur quelque chose de ludique ??

  4. Spring Powered Camera « Papervision3D - Developers Says:

    [...] Powered Camera By C4RL05 Benoit Beauséjour has developed a spring powered camera class that works beautifully and is very easy to use. Implements spring physics to attach a 3D camera to [...]

  5. localToGlobal » Blog Archive » news review -> 4th week of 2009 Says:

    [...] > Spring physics powered 3D camera for Away3D and Papervision at Agit8 [...]

  6. philipperoy Says:

    Complètement fou !

  7. 3D Ball Adventure (JigLibMotionSpringCamera3D) - Part 3 | AlmostLogical.com Says:

    [...] the direction it is facing. Part of the camera’s smooth motion is achieved by extending the SpringCamera3D class. While this camera does have specific job, I know that there are a lot of uses for a camera like [...]

  8. Agnosix: Collige Rosas Says:

    [...] camera para PV3D Una clase muy util desarrollada por agit8. También disponible para away 3D. Merece un vistazo por lo menos. Warning: getimagesize() [function.getimagesize]: Read error! in [...]

  9. Flash Summer Camp Berlin - Think In 3D Workshop - Follow-up | analogdesign’s lab | Cedric M. (aka maddec) Says:

    [...] Spring Camera: a camera with natural movement useful, for example, for FPS or games: Spring Camera by Agit8 [...]

  10. Yogesh Says:

    Hi,

    Is there a way to find out that the Spring Camera movement has ended?

    Thanks.

  11. Benoit Beausejour Says:

    Hi Yogesh,

    unfortunately no, since the camera is “in theory” always moving …meaning that it’s not tweening it’s perpetually adjusting it’s position relative to the target.

    You COULD monitor it’s position and if it’s static then you could implement your own event logic to detect the end of movement though.

Leave a Reply


capsule omeprazole cialis rx buy ultram free levitra samples treatment for herpes buy cialis cheap loss of hair buy body building supplement pharmacy lipitor buy cialis on line augmentin doses new levitra ultram information healthy immune system allergic benadryl synthroid tablets antibiotics and dogs purchase cialis online without prescription how to treat flu xanax interactions with other medicines claritin pill hoodia order buy cialis without prescription ranitidine pregnancy cialis online without prescription herpes cures that work augmentin doses cheapest generic cialis online online stores hair loss products levitra without prescription vitamin c buy cheap amoxil without prescription online pharmacy viagra buy cialis on line buy levitra approved cialis fda about cialis viagra order online cialis prescription buy phentermine nausea cure toprol 50mg antibiotic chlamydia cialis levitra viagra menopause gum buy cialis online now buy buspar prednisone 10mg dogs weight buy cheap cialis dogs antidepressants buy cheap tadalafil uk cialis without rx clomid buy viagra online australia famotidine 20mg stomach parasites free samples viagra high blood calcium levels effexor dose hyaluronic acid buy buy cialis online serevent generic ibuprofen withdrawal otc claritin cialis and purchase coumadin side effects total health solutions buy tramadol cheap fertility in women purchase cialis online without prescription cialis without a prescription buy bone maker strontium cheap alcoholism treatment risperdal anxiety buy buspar can i get a viagra today levitra effect augmentin doses prozac antidepressants ways to make your penis bigger buy phentermine without prescription drug zithromax buyviagra cialis how do you treat lung cancer purchase meds without prescription how to purchase cialis drugs for diabetes valium and alcohol generic viagra on line how to white teeth motilium buy alternative treatment arthritis levitra cialis viagra cheap impotence drug generic cialis delivery phentermine by fedex sale levitra cialis prescription online order on line medicine without prescriptions abscess infection cats buy celexa how buy viagra lasix side effects chronic heart failure cheap msm buy lasuna cheap viagra order online promethazine tablets how to get viagra purchase levitra online pain meds without prescriptions stop hair loss buspar online viagra experience increase your erection clonazepam overdose xanax dosages order phentermine alavert drug how to cure acne viagra online usa cialis canadian pharmacy buy precose cialas on line buy amiodarone drug contraception pill levitra overnight buy zovirax finasteride prescription claritin 10mg levitra cheap online viagra for sex all natural antibiotics pain in left side home treatment for edema glucophage cialis canada pharmacy buy cialis online vpxl herbal levitra without prescription levitra online online prescription for cialis rx-viagra cat skin disorders how to treat prostate cancer yeast diflucan what does viagra do to females zyban how to use cialis advice viagra online without prescription