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!



















January 22nd, 2009 at 5:23 pm
As if I’m not biased.
This ROCKS.
January 22nd, 2009 at 6:19 pm
Very handy, thanks.
January 22nd, 2009 at 6:31 pm
very nice !!! bravo dieu !!! toujours aussi fort !!! lol
à quand ce bel effet sur quelque chose de ludique ??
January 23rd, 2009 at 6:04 am
[...] 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 [...]
January 23rd, 2009 at 11:43 am
[...] > Spring physics powered 3D camera for Away3D and Papervision at Agit8 [...]
January 25th, 2009 at 3:42 pm
Complètement fou !
February 23rd, 2009 at 12:35 am
[...] 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 [...]
February 24th, 2009 at 2:22 am
[...] 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 [...]
July 13th, 2009 at 8:52 am
[...] Spring Camera: a camera with natural movement useful, for example, for FPS or games: Spring Camera by Agit8 [...]
October 29th, 2009 at 12:07 am
Hi,
Is there a way to find out that the Spring Camera movement has ended?
Thanks.
October 29th, 2009 at 5:04 pm
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.