Greetings from Solaria! This is the first dev blog post of many as I progress on the development of Solaria Tactics. Hopefully these will be useful for other developers on their long journeys in game development.
Since the game is an isometric tactics game with simultaneous turns I really need to have a good camera control script so you can see what you need to and reposition it quickly for a better view in the heat of the moment. Unfortunately all the scripts I found online were incomplete at best and had glaring faults at worst.
I needed something that had
- Click and drag panning that exactly matched the mouse movement (none of this pan speed nonsense that either causes the map to move very slowly or fly off the screen)
- Zoom in and out with the scroll wheel
- Rotate around the tile that your mouse is over with middle click drag, and also snap to the isometric angles (45, 135, 225, 315)
- And the bonus panning the camera with the arrow keys
Several months ago I had a script that did nearly all I needed it to do but I discovered it had an interesting bug. When panning up the script was moving the camera’s y position up so it would get higher and higher. This looked correct in the game view because of the camera’s orthographic projection, but the problem is that if you pan to the end of the map, rotate back around and do it again the camera ends up so high that the map gets cut off out of the clipping planes.
While fixing the mouse panning problem I also tackled the rotation with the middle mouse click and dragging both of which took longer than expected (as usual of course) partially because I never took linear algebra which would have helped hah.
To start with, here’s what the camera movement looks like in the game (art is temporary, and not how it will look in the final game blah blah blah…)
And here’s what it looks like in the unity editor with the camera moving around:
My camera setup should be pretty standard for an isometric game:
The trick to getting the camera moving properly was to convert the mouse up and down movement into a vector with just x and z components using the camera’s forward vector (which is pointing down towards the map). The left and right movement can then rotate that vector 90 degrees around the y axis to use for horizontal panning.
So without further ado, here’s the script. Unless you have a very specific set up this probably won’t work right out of the gate but should be quite easy for you to adapt to your setup.
Thanks for reading and hopefully you learned something you can use!
Liked this post?
Sign up and be the first to see new posts!
No spam, no nonsense, no guarantees, no rights reserved, probably.