Wednesday, February 20, 2013

Camera Control

I’ll talk a bit about the camera control since that is simple enough and my next post will detail the design of the CGameState (which is far more complex but I’ll try to do the minimal version of it to get a game working).

The camera control uses the familiar WASD and the more old-school arrow keys.  Later I may have a CConfigurationManager which maps actions to specific keys (in a settings control) similar to most games.  Since I’m not sure on how often RTS controls are customisable (I’ve really only seen pro-league RTS players do such a thing because of the vast number of keys, they try to reduce it to the 1234/QWER/ASDF control scheme to increase APM) I will put that as a later idea.

Basically, as you press W, you will move up on the map.  Your z-plane coordinates are locked.  I may implement zooming later but I’ll want to fix up the isometric view first (or not, I’m still on the fence on this since I’m not sure if it looks that much more weird using a typical 3d projection for an RTS).

CCameraController will likely be an object inside CInputController.  When the state is GAME then the CInputController will inject keys to the CCameraController object it holds.  It will inject everything to it and the CCameraController can ignore as needed (to keep it a blackbox).  Later optimisation might want to break that encapsulation but for now I’ll leave it at that.

For CCameraController I’ll simply do something like this:

  • KeyboardKeyDown
    • W or UP ARROW
      • set isMovingUp = true, unless already moving down
    • A or LEFT
      • set isMovingLeft = true, unless already moving right
    • S or DOWN
      • isMovingDown = true, unless already moving up
    • D or RIGHT
      • isMovingRight = true, unless already moving left
  • KeyboardKeyUp
    • W or UP ARROW
      • set isMovingUp = false
    • A or LEFT
      • set isMovingLeft = false
    • S or DOWN
      • isMovingDown = false
    • D or RIGHT
      • isMovingRight = false
  • FrameRenderingQueued (or something equivalent)
    • MoveCamera
      • isMoving
        • Depending on direction add x or y
        • Amount = velocity * timeSinceLastFrame
        • Do this for every direction which is true (allowing you to do up-right movement for instance)
        • Only up to max map coordinates

And that should be sufficient for a very basic camera control scheme.

1 comment:

  1. I like the idea of QWER, ASDF being analogous to icons in whatever interface you have planned. They did that in Rise of Legends and I found it super-useful. Makes me sorta feel that SC2 should have done that as well by default (I'm a little too used to the hotkeys to switch now though).

    I think that moving the camera by mouse-scrolling and using the arrow keys is pretty good.

    ReplyDelete