Island War Day 7
Today, I’ve got some new screen shots! Read on 🙂
Over the weekend, I implemented proper camera and terrain selection controls. Getting keyboard, mouse and gamepad working at the same time proved a bit of a nightmare. PC RTS players will expect the arrow keys to move around their view and the mouse to be usable as a selection tool. XBox 360 RTS players need some way of telling the game where to place buildings, but the gamepad isn’t suited for this task as well as the mouse is.
So I decided to split my terrain into a regular grid in which a terrain cursor can be moved. The grid is in units of 3×3 terrain quads, which allows me to add some detail to the terrain on the sub-grid-cell level. Otherwise, it would look fairly obvious to the player that the terrain is based on a heightmap with regular X/Y samples.
I originally wanted the camera work like a helicopter that was trying to keep the player’s terrain cursor in its view, but the way a helicopter tilts to change its position is exactly the opposite of what I want: If the cursor moves to the north, the helicopter would have to tilt forwards (showing even less of the north) until the helicopter itself had caught up.
So, instead of following the helicopter approach, I ran with the exact opposite. If the terrain cursor moves north, the camera will tilt to still show the cursor and then gradually drift north itself. It can also zoom in and out or rotate around the terrain cursor to view the map from other directions.
The hard part was unifying mouse, keyboard and game pad. The keyboard should move the camera without moving the terrain cursor. The mouse should move the terrain cursor to the grid cell under the mouse cursor. And the game pad, finally, should move both the terrain cursor and the camera. And if the player uses unlikely combinations of input devices, such as mouse and game pad or keyboard and game pad, the input system shouldn’t be totally worthless.
I did it by keeping a permanent camera target cell (that is independent of the terrain cursor). If the terrain cursor is moved by the game pad, the target cell is updated as well. If the terrain cursor is moved by the mouse, it isn’t. The keyboard, then, adjusts the camera target cell on the sub-grid-cell level without moving the terrain cursor.
A weird mix of controls, but as far as I can tell, it’s very intuitive and works well 🙂