Spring Chase Camera

A place to show off your latest screenshots and for people to comment on them. Only start a new thread here if you have some nice images to show off!
User avatar
liamrudel
Gremlin
Posts: 150
Joined: Tue Oct 21, 2008 10:35 am
Location: Ireland
Contact:

Spring Chase Camera

Post by liamrudel »

Hi guys,

Here's a spring chase camera I did for a recent project. Fell free to use it wherever you like.
Image

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!
User avatar
xadhoom
Minaton
Posts: 973
Joined: Fri Dec 28, 2007 4:35 pm
Location: Germany
x 1

Re: Spring Chase Camera

Post by xadhoom »

Very cool! Thanks for sharing! Maybe I can implement your approach with a PhysX Joint and an Actor for correct collsion, too...

xad
SirGolan
Gnoblar
Posts: 20
Joined: Wed Apr 02, 2008 1:32 am
x 3

Re: Spring Chase Camera

Post by SirGolan »

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.
MV3D -- Open Source Virtual World and Multiplayer Game Framework.
User avatar
liamrudel
Gremlin
Posts: 150
Joined: Tue Oct 21, 2008 10:35 am
Location: Ireland
Contact:

Re: Spring Chase Camera

Post by liamrudel »

Cool, Glad I made it easy to understand!
The secret of creativity..... is knowing how to hide your sources!
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Re: Spring Chase Camera

Post by jacmoe »

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? :)
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
my.name
Goblin
Posts: 222
Joined: Tue Aug 08, 2006 2:58 pm
Location: Moscow
x 1

Re: Spring Chase Camera

Post by my.name »

=)
Image
Image
User avatar
nikki
Old One
Posts: 2730
Joined: Sat Sep 17, 2005 10:08 am
Location: San Francisco
x 13
Contact:

Re: Spring Chase Camera

Post by nikki »

Yay for MyGUI! So, looks like it worked out for you?
User avatar
liamrudel
Gremlin
Posts: 150
Joined: Tue Oct 21, 2008 10:35 am
Location: Ireland
Contact:

Re: Spring Chase Camera

Post by liamrudel »

Ya got it all sorted in the end.

When I get some time I'll turn this into a wiki article :D
The secret of creativity..... is knowing how to hide your sources!
User avatar
zarfius
Gnome
Posts: 367
Joined: Wed Jan 03, 2007 12:44 pm
Location: Brisbane, Australia
x 13
Contact:

Re: Spring Chase Camera

Post by zarfius »

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 :)
Craftwork Games - hand crafted entertainment.
http://www.craftworkgames.com/
User avatar
liamrudel
Gremlin
Posts: 150
Joined: Tue Oct 21, 2008 10:35 am
Location: Ireland
Contact:

Re: Spring Chase Camera

Post by liamrudel »

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!
The secret of creativity..... is knowing how to hide your sources!
mickeyren
Greenskin
Posts: 142
Joined: Thu Dec 18, 2008 11:32 am

Re: Spring Chase Camera

Post by mickeyren »

Hey liamrudel

I just want to let you know your site is really broken.
User avatar
liamrudel
Gremlin
Posts: 150
Joined: Tue Oct 21, 2008 10:35 am
Location: Ireland
Contact:

Re: Spring Chase Camera

Post by liamrudel »

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!
mickeyren
Greenskin
Posts: 142
Joined: Thu Dec 18, 2008 11:32 am

Re: Spring Chase Camera

Post by mickeyren »

hmm strange your site does look fine on IE.
broken.jpg
broken.jpg (56.93 KiB) Viewed 8534 times
Here's what I see on my firefox. Must be only me or my firebug and web developer toolbar plugins.
User avatar
liamrudel
Gremlin
Posts: 150
Joined: Tue Oct 21, 2008 10:35 am
Location: Ireland
Contact:

Re: Spring Chase Camera

Post by liamrudel »

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!
mickeyren
Greenskin
Posts: 142
Joined: Thu Dec 18, 2008 11:32 am

Re: Spring Chase Camera

Post by mickeyren »

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.
User avatar
liamrudel
Gremlin
Posts: 150
Joined: Tue Oct 21, 2008 10:35 am
Location: Ireland
Contact:

Re: Spring Chase Camera

Post by liamrudel »

Ok, Thanks all the same :D
The secret of creativity..... is knowing how to hide your sources!
User avatar
globalsinner
Kobold
Posts: 30
Joined: Wed Jul 01, 2009 4:30 pm

Re: Spring Chase Camera

Post by globalsinner »

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.. :)
your life was ended by mermaids... \m/
User avatar
liamrudel
Gremlin
Posts: 150
Joined: Tue Oct 21, 2008 10:35 am
Location: Ireland
Contact:

Re: Spring Chase Camera

Post by liamrudel »

Glad it helped, it's not much but a good starting point!
The secret of creativity..... is knowing how to hide your sources!
User avatar
Handicap
Halfling
Posts: 62
Joined: Mon Apr 09, 2007 5:56 pm
Location: Poland

Re: Spring Chase Camera

Post by Handicap »

Yyym whats da difference? Ive used interpolation for my TPP cam, like:

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;
Can u tell me what are benefits of ur camera?
User avatar
liamrudel
Gremlin
Posts: 150
Joined: Tue Oct 21, 2008 10:35 am
Location: Ireland
Contact:

Re: Spring Chase Camera

Post by liamrudel »

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!
User avatar
koirat
Orc
Posts: 446
Joined: Mon Feb 25, 2008 7:56 pm
x 13

Re: Spring Chase Camera

Post by koirat »

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.
This is a block of text that can be added to posts you make. There is a 255 character limit.
User avatar
liamrudel
Gremlin
Posts: 150
Joined: Tue Oct 21, 2008 10:35 am
Location: Ireland
Contact:

Re: Spring Chase Camera

Post by liamrudel »

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!
User avatar
Handicap
Halfling
Posts: 62
Joined: Mon Apr 09, 2007 5:56 pm
Location: Poland

Re: Spring Chase Camera

Post by Handicap »

No, I use constant FPS and accumulator, sth like:

Code: Select all

gameloop
{
  accumulator = accumulator + timeDelta
  while (accumulator > frameTime)
   {
       doGameLogicFrame()
      accumulator = accumulator - frameTime
   }
  render()
}
So I have constant frame Time (i.e. 0.01666) and no fps-relative problems within logic and physics (includin camera)
User avatar
koirat
Orc
Posts: 446
Joined: Mon Feb 25, 2008 7:56 pm
x 13

Re: Spring Chase Camera

Post by koirat »

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.
Post Reply