Jump to content
  • Advertisement
Sign in to follow this  

RPG Style Camera

This topic is 3144 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys, I am trying to finish up my camera system but so far I am stuck. Everything works appropriately up until now as far as rotating it around the character and zooming in/out and so on, but I am trying to smooth out the zoom. (Not actually zoom, just make the camera closer/farther away from the player) Heres what I have currently...
bool WorldState::mouseMoved(const OIS::MouseEvent &arg)
      // If we are in camera-pivote state, spin/pitch the camera based
      // on relative mouse movement.
      // Get rid of the * -1.0 to invert the mouse movement
      chaseCam->spin(Degree(arg.state.X.rel * 0.14) * -1.0);
      chaseCam->pitch(Degree(arg.state.Y.rel * 0.1) * -1.0);
      return true;

      static Real zDist;

      zDist = (-0.05f * arg.state.Z.rel);
      chaseCam->getCamera()->moveRelative(Vector3(0.0f, 0.0f, zDist));

   return guiCanvas->injectMouseMove(arg.state.X.abs, arg.state.Y.abs);
Now the problem is when you use the mousewheel, its kind of jerky as it zooms closer/further from the player. I am trying to find someway to implement something like WoW or any other number of RPGs have, where when you zoom it kind of smooth transitions from like a node to the next node, with the first node being at the character, and the end node being X distance from the player. I have not really found anything from sites/snippets covering this though, so I am hoping you guys can help. I found a demo application from Ogre3D that makes the mouse follow a track, but it seems more oriented for doing an automated camera in like a video or something, so not sure if I should use it in this case (or if it would work at all)

Share this post

Link to post
Share on other sites
How about zooming with a constant speed?
Store the needed 'node' in a variable.
If you scroll down with the mouse, you increase this variable, when you scroll up, you decrease it. Store the current (displayed) 'node' too.
If the current node is smaller than needed, increase it with constant speed, if larger, decrease it.

//scroll handling
needed_node += step;
needed_node -= step;

//game loop
if( current_node < needed_node )
current node += delta_time*zoom_speed;
else if( current_node > needed_node )
current node -= delta_time*zoom_speed;

So the zooming can only change with a limited value per frame, so it won't be jerky.
step is much bigger than delta_time*zoom_speed It's not precise, but I think you get the idea.

Warcraft III (the rts) uses this method (at least the result is the same). Or you could do some movement interpolation too based of the few former zooming actions, but that's beyond me.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!