Spring Chase Camera
- liamrudel
- Gremlin
- Posts: 150
- Joined: Tue Oct 21, 2008 10:35 am
- Location: Ireland
- Contact:
Spring Chase Camera
Hi guys,
Here's a spring chase camera I did for a recent project. Fell free to use it wherever you like.
SpringCam is a demo app which shows how to use a spring to implement a nice smooth chase camera for driving, flying or third person games.
The demo includes controls to adjust the mass, stiffness and dampening of the spring that attaches the camera to the player.
Source Download:
http://www.liamrudel.com/?page_id=423
Here's a spring chase camera I did for a recent project. Fell free to use it wherever you like.
SpringCam is a demo app which shows how to use a spring to implement a nice smooth chase camera for driving, flying or third person games.
The demo includes controls to adjust the mass, stiffness and dampening of the spring that attaches the camera to the player.
Source Download:
http://www.liamrudel.com/?page_id=423
The secret of creativity..... is knowing how to hide your sources!
- xadhoom
- Minaton
- Posts: 973
- Joined: Fri Dec 28, 2007 4:35 pm
- Location: Germany
- x 1
Re: Spring Chase Camera
Very cool! Thanks for sharing! Maybe I can implement your approach with a PhysX Joint and an Actor for correct collsion, too...
xad
xad
- Nauk
- Gnoll
- Posts: 653
- Joined: Thu May 11, 2006 9:12 pm
- Location: Bavaria
- x 36
- Contact:
Re: Spring Chase Camera
Very useful, thanks for sharing
ARTIFEX TERRA 3D - Artist-friendly, free and easy WYSIWYG realtime outdoor scene Editor & Painter
New loader now with Ogre::Terrain support: Addons for Artifex on SourceForge
MOC - Minimal Ogre Collision & Mousepicking
Simple TerrainMaterialGenerator for the use of standard Ogre material with Ogre::Terrain
Support me on Patreon
-
- Gnoblar
- Posts: 20
- Joined: Wed Apr 02, 2008 1:32 am
- x 3
Re: Spring Chase Camera
Pairing something like this up with a physics engine for collisions works great as xadhoom mentioned. That's what I've been using lately and it makes for smooth camera moves. Though you have to watch out for instances where the camera gets caught behind something because the player went through a doorway and then strafed to the side before the camera followed them through. I think I have a video of that happening in MV3D somewhere.
Thanks for sharing the code! It was very easy to understand and should be helpful to a lot of people.
Thanks for sharing the code! It was very easy to understand and should be helpful to a lot of people.
MV3D -- Open Source Virtual World and Multiplayer Game Framework.
- liamrudel
- Gremlin
- Posts: 150
- Joined: Tue Oct 21, 2008 10:35 am
- Location: Ireland
- Contact:
Re: Spring Chase Camera
Cool, Glad I made it easy to understand!
The secret of creativity..... is knowing how to hide your sources!
- jacmoe
- OGRE Retired Moderator
- Posts: 20570
- Joined: Thu Jan 22, 2004 10:13 am
- Location: Denmark
- x 179
- Contact:
Re: Spring Chase Camera
Thanks for sharing this! How to setup a camera system is oft requested here.
Which leads me to suggest: how about writing a small wiki article?
And let it not be buried in this forum?
Which leads me to suggest: how about writing a small wiki article?
And let it not be buried in this forum?
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
- my.name
- Goblin
- Posts: 222
- Joined: Tue Aug 08, 2006 2:58 pm
- Location: Moscow
- x 1
- nikki
- Old One
- Posts: 2730
- Joined: Sat Sep 17, 2005 10:08 am
- Location: San Francisco
- x 13
- Contact:
- liamrudel
- Gremlin
- Posts: 150
- Joined: Tue Oct 21, 2008 10:35 am
- Location: Ireland
- Contact:
Re: Spring Chase Camera
Ya got it all sorted in the end.
When I get some time I'll turn this into a wiki article
When I get some time I'll turn this into a wiki article
The secret of creativity..... is knowing how to hide your sources!
- zarfius
- Gnome
- Posts: 367
- Joined: Wed Jan 03, 2007 12:44 pm
- Location: Brisbane, Australia
- x 13
- Contact:
Re: Spring Chase Camera
Very nicely done.
I'm at work so I'm not able to run it at the moment, but looking over the code is enough to get the general idea. Your coding style is very similar to mine, I think I'll also use your GameState class (if that's okay with you )
It'd be interesting to see how much code you have to change in your design if you decide to implement a physics engine. I found that my GameObject class had to change significantly from something very similar to yours.
I second the idea of a wiki article
I'm at work so I'm not able to run it at the moment, but looking over the code is enough to get the general idea. Your coding style is very similar to mine, I think I'll also use your GameState class (if that's okay with you )
It'd be interesting to see how much code you have to change in your design if you decide to implement a physics engine. I found that my GameObject class had to change significantly from something very similar to yours.
I second the idea of a wiki article
Craftwork Games - hand crafted entertainment.
http://www.craftworkgames.com/
http://www.craftworkgames.com/
- liamrudel
- Gremlin
- Posts: 150
- Joined: Tue Oct 21, 2008 10:35 am
- Location: Ireland
- Contact:
Re: Spring Chase Camera
I got the framework from a thread around on the forum. Not sure who I should credit as they adapted it from someone else.
Question: Whats the story with that anyway. If someone posts code like I did is it ok to use it without credit?
Well I'm using Havok physics in another game and am using the same camera code but don't have camera collision, it runs on basically one line of code, can't see it being much different, I suppose after you get the new camera position update it again if there was a collision.
As in:
1. Get camera position from spring
2. Check for collision, and move the camera to uncolided position
As someone else mentioned i'm sure doorways may cause problems. When I get some more time i'll see if i can use a rigidbody in Havok attached to the camera for collision checking.
I also really wanna do the wiki article, will do when i get some free time!
Question: Whats the story with that anyway. If someone posts code like I did is it ok to use it without credit?
Well I'm using Havok physics in another game and am using the same camera code but don't have camera collision, it runs on basically one line of code, can't see it being much different, I suppose after you get the new camera position update it again if there was a collision.
As in:
1. Get camera position from spring
2. Check for collision, and move the camera to uncolided position
As someone else mentioned i'm sure doorways may cause problems. When I get some more time i'll see if i can use a rigidbody in Havok attached to the camera for collision checking.
I also really wanna do the wiki article, will do when i get some free time!
The secret of creativity..... is knowing how to hide your sources!
-
- Greenskin
- Posts: 142
- Joined: Thu Dec 18, 2008 11:32 am
Re: Spring Chase Camera
Hey liamrudel
I just want to let you know your site is really broken.
I just want to let you know your site is really broken.
- liamrudel
- Gremlin
- Posts: 150
- Joined: Tue Oct 21, 2008 10:35 am
- Location: Ireland
- Contact:
Re: Spring Chase Camera
Can you explain, it all seems fine to me, what do you mean by broken?
The secret of creativity..... is knowing how to hide your sources!
-
- Greenskin
- Posts: 142
- Joined: Thu Dec 18, 2008 11:32 am
Re: Spring Chase Camera
hmm strange your site does look fine on IE.
Here's what I see on my firefox. Must be only me or my firebug and web developer toolbar plugins.
Here's what I see on my firefox. Must be only me or my firebug and web developer toolbar plugins.
- liamrudel
- Gremlin
- Posts: 150
- Joined: Tue Oct 21, 2008 10:35 am
- Location: Ireland
- Contact:
Re: Spring Chase Camera
Can you tell me what version of firefox you are using and what resolution?
The secret of creativity..... is knowing how to hide your sources!
-
- Greenskin
- Posts: 142
- Joined: Thu Dec 18, 2008 11:32 am
Re: Spring Chase Camera
Hi liamrudel
I manage to track it down. That happens when my firebug's console is enabled. So its me not your site. Sorry for the confusing report.
I manage to track it down. That happens when my firebug's console is enabled. So its me not your site. Sorry for the confusing report.
- liamrudel
- Gremlin
- Posts: 150
- Joined: Tue Oct 21, 2008 10:35 am
- Location: Ireland
- Contact:
Re: Spring Chase Camera
Ok, Thanks all the same
The secret of creativity..... is knowing how to hide your sources!
- globalsinner
- Kobold
- Posts: 30
- Joined: Wed Jul 01, 2009 4:30 pm
Re: Spring Chase Camera
Hey there,
Thanks a lot for this. This works great tho I had to get rid of MyGUI as it does not work on my environment. Could be some problem due to differences in the environment in which the dll was compiled and the one I have (VS 2008, using Ogre 1.6). Still it works great and has helped a lot. I'm currently customising it for a small demo I'm workin on..
Thanks a lot for this. This works great tho I had to get rid of MyGUI as it does not work on my environment. Could be some problem due to differences in the environment in which the dll was compiled and the one I have (VS 2008, using Ogre 1.6). Still it works great and has helped a lot. I'm currently customising it for a small demo I'm workin on..
your life was ended by mermaids... \m/
- liamrudel
- Gremlin
- Posts: 150
- Joined: Tue Oct 21, 2008 10:35 am
- Location: Ireland
- Contact:
Re: Spring Chase Camera
Glad it helped, it's not much but a good starting point!
The secret of creativity..... is knowing how to hide your sources!
- Handicap
- Halfling
- Posts: 62
- Joined: Mon Apr 09, 2007 5:56 pm
- Location: Poland
Re: Spring Chase Camera
Yyym whats da difference? Ive used interpolation for my TPP cam, like:
Can u tell me what are benefits of ur camera?
Code: Select all
cam.DestPos = (calculate point behind player and raycast it to avoid ghosting)
cam.Pos = cam.Pos + (cam.DestPos - cam.Pos) * cam.Interpolation;
- liamrudel
- Gremlin
- Posts: 150
- Joined: Tue Oct 21, 2008 10:35 am
- Location: Ireland
- Contact:
Re: Spring Chase Camera
I'm not claiming this is the best way, so perhaps there are no benifits over your method. It's just one approach. A spring using Hookes Law, gives a nice motion to the camera.
The secret of creativity..... is knowing how to hide your sources!
- koirat
- Orc
- Posts: 446
- Joined: Mon Feb 25, 2008 7:56 pm
- x 13
Re: Spring Chase Camera
Handicap is your cam interpolation based on time offset or it is just a number, and every frame you are just multiplying difference by interpolation.
I'm askin cuz i made TPP camera with tightness parameter, but my implementation is not time offsest based but frame based. I will change it to spring based camera soon. So it's behavior is not going to be FPS dependant.
I'm askin cuz i made TPP camera with tightness parameter, but my implementation is not time offsest based but frame based. I will change it to spring based camera soon. So it's behavior is not going to be FPS dependant.
This is a block of text that can be added to posts you make. There is a 255 character limit.
- liamrudel
- Gremlin
- Posts: 150
- Joined: Tue Oct 21, 2008 10:35 am
- Location: Ireland
- Contact:
Re: Spring Chase Camera
Just to note, as far as I remember I left my spring frame rate dependent, to fix this just mulitply by time since last frame when getting velocity.
The secret of creativity..... is knowing how to hide your sources!
- Handicap
- Halfling
- Posts: 62
- Joined: Mon Apr 09, 2007 5:56 pm
- Location: Poland
Re: Spring Chase Camera
No, I use constant FPS and accumulator, sth like:
So I have constant frame Time (i.e. 0.01666) and no fps-relative problems within logic and physics (includin camera)
Code: Select all
gameloop
{
accumulator = accumulator + timeDelta
while (accumulator > frameTime)
{
doGameLogicFrame()
accumulator = accumulator - frameTime
}
render()
}
- koirat
- Orc
- Posts: 446
- Joined: Mon Feb 25, 2008 7:56 pm
- x 13
Re: Spring Chase Camera
liamrudel wrote:Just to note, as far as I remember I left my spring frame rate dependent, to fix this just mulitply by time since last frame when getting velocity.
You mean in this place ??
Code: Select all
//Add velocity to old camera position
mCameraPos = mCameraPos + mVelocity * timeOffset.
This is a block of text that can be added to posts you make. There is a 255 character limit.