mandag den 31. oktober 2016

Camera Control


Hello i'm Lars from the HiddenGames Programmer Team.

Recently i've been working on a Camera Control Script for the video game Corporate Quest with Thorulf,  it turned out well and is now in full use in the demo we are making. 

What is it and why did you make it?
The reason why we made this was for the feeling of dragging around the map like it was a paper. We also wanted to limit the players view, to ensure they focus on Seattle first before the other parts of the map. The camera movement was decided to be free map movement around a dedicated part of the game, where you can zoom in and out on cities.


How do you use it?
It works like this:
  • Hit the right mousebutton while moving the mouse in the opposite direction of where you want to go
  • Zoom in and out with the mouse scroller to show more or less of the map 
How does the script looks like?
The script would be too long to describe completely as it fills 100 lines, but i'll highlight the most interesting parts

Rightclick mouse and drag
The script checks for input from the right mouse button, if there's input it takes the input and inverts it. The script then checks the limit that was set in the editor to see if it can move and if it can, then the code will move the camera.

// Camera dragging movement
if (Input.GetKey(KeyCode.Mouse1)) { 

// Gets the movement in unity units and inverts it for correct controls
Vector3 input = (Camera.main.ScreenToWorldPoint(Input.mousePosition) - Camera.main.ScreenToWorldPoint(lastMousePos)) * -1;

//Gets the screen size for limiting of movement
Vector2 camPosTopRight = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height, 0));
Vector2 camPosBottomLeft = Camera.main.ScreenToWorldPoint(new Vector3(0, 0, 0));

//moves the camera if movement doesnt cross the limit
if (camPosBottomLeft.x + input.x > camLimitBottomLeft.x && camPosTopRight.x + input.x < camLimitTopRight.x) transform.Translate(new Vector3(input.x, 0));

if(camPosBottomLeft.y + input.y > camLimitBottomLeft.y && camPosTopRight.y + input.y < camLimitTopRight.y)
transform.Translate(new Vector3(0, input.y));

lastMousePos = Input.mousePosition;
}

Figure 1 - Code behind the mouse drag movement script


Camera Limit
To prevent the player from scrolling out of the map, we wanted to make limits in the editor to fit the map as it develops, you can drag two vectors in the editor to determine the camera limits.


Figure 2 - Camera Limits in the scene editor


Related Posts:

  • Get ready to rumble!Seriously, get ready because these bad boys are gonna rock your world. Here is the last three Exstractor sprites that were made for Corporate Quest. They were of course made using the same vector style graphics that were ment… Read More
  • Our very own truckHours of work later and we've finally got a truck to transport supplies from A to B. Based off of the american truck design, this truck is one of the key art assets for the visual presentation of our game's system. Theref… Read More
  • The first 4 resourcesYou get a resource, and you get a resource, everyone gets a resource... The first batch of resources have been made and are ready for use inside the game. The four different resources: Wheat, Bagels, Oil, and Plastic. T… Read More
  • Moodboards/ ArtstyleLet's set the mood To set up the style for the game we chose to research and develop a color style to capture the player's attention, and an art style for the in-game assets to specify the look of the game. Choosing a colo… Read More
  • Heatmap To give the player a visualisation of where the largest amount of resources are located, we've created a heatmap. This will help the player choose the optimal location for the extractor building.  The heatmap scrip… Read More

0 kommentarer:

Send en kommentar