This section describes the camera in the role controller
This section describes some of the camera's reference scenarios today, with a little bit of footage and screens and the fur of the scene's location.
1 Follow lead (stand-alone RPG, online games)
First introduce a commonly used lens follow, refer to some commonly used online games, etc., this category is characterized by the role of the center, the lens followed the protagonist, and can be right-click swipe to rotate the 3D scene
The first process follows,
First adjust the approximate position of the camera,
Click on the top left corner to adjust the camera angle and watch the camera
Adjust the approximate angle, I set the foot of the foot in the rear, and then add a script to the lens
Private Gameobject player; Private Vector3 Cameratoplayer; void Awake () { //Get pig foot object player = Gameobject.findgameobjectwithtag (tags.player); The relative position of the camera and the character cameratoplayer = transform.position-player.transform.position; } void Fixedupdate () { ///Move camera position follow pig feet camera current position camera move target position speed transform.position = Vector3.lerp (transform.position, Player.transform.position + Cameratoplayer, 1.5f); }
So the camera will barely catch up with the pig's foot.
Then we set the direction of the lens to move through the mouse stroke screen.
Private Gameobject player; Private Vector3 Cameratoplayer; void Awake () { //Get pig foot object player = Gameobject.findgameobjectwithtag (tags.player); The relative position of the camera and the character cameratoplayer = transform.position-player.transform.position; } void Update () { float mousex; float Mousey; if (Input.getmousebutton (0)) { MouseX = Input.getaxis ("Mouse X") * TEN; Mousey =-input.getaxis ("Mouse Y") * TEN; Transform. Rotate (Mousey, MouseX, 0); } Move the camera position follow the pig's foot camera current position camera move target position speed transform.position = Vector3.lerp (Transform.position, Player.transform.position + Cameratoplayer, 1.5f); }
Here set the left button to adjust the camera angle, although the simple implementation, when the camera angle attribute Z has been changed, the actual use of the effect is not very good.
2. First view (CF,CS)
The 300 million-class game is dominated by the first view and has a sense of generational.
To achieve the first view, put the camera on the head of the pig's foot
Then adjust the initial field of view
In this way, camera is a sub-object of the pig's foot, it will move more with the pig
Now processing camera angle, in the big 300 million, after the game Mouse point will become quasi-heart, we based on the mouse in the screen track to change the camera angle properties
Add a script to the camera
void Update () { transform. Rotate (-input.getaxis ("Mouse Y"), Input.getaxis ("Mouse X"), 0);}
is not very simple, the rotate parameter refers to the angle of rotation around the XYZ axis. After running the game
It's really a feeling.
Here are a few questions, 1 lens angle needs to be fine-tuned, 2 turn back to see yourself (this is related to the initial position)
3. Third view (lol dota)
The last introduction of a perspective is the famous pupil series of God perspective. This perspective is characterized by a top-down view, which drags the screen as it touches the edge of the screen.
Let's adjust the camera angle first.
There is no need to change the camera angle, as long as the camera's location is changed, the y-axis is controlled by the roller
Set the wheel first.
void Update () { ///scroll wheel return value if (Input.getaxis ("Mouse scrollwheel") = 0) { //Judging range if ( TRANSFORM.POSITION.Y +input.getaxis ("Mouse scrollwheel") >= 6.4 && TRANSFORM.POSITION.Y + input.getaxis (" Mouse scrollwheel ") <=9.4) { transform.position + = new Vector3 (0, Input.getaxis (" Mouse scrollwheel "), 0); } } }
Then set the screen movement, when the mouse moves to the edge of the camera, the idea is to get the screen size, get the mouse position, determine whether the mouse on the edge, and then get the mouse moving vector to move the camera
Resolution screen; void Start () {screen = screen.currentresolution; } void Update () {///scroll wheel return value if (Input.getaxis ("Mouse scrollwheel")! = 0) {//Judging range if (Transform.position.y +input.getaxis ("Mouse scrollwheel") >= 6.4 && TRANSFORM.POSITION.Y + input.g Etaxis ("Mouse scrollwheel") <=9.4) {transform.position + = new Vector3 (0, Input.getaxis ("Mou Se scrollwheel "), 0); }}//Determine mouse position if (Mousescreen ()) {//Move camera position Transform.positio n + = new Vector3 (Input.getaxis ("Mouse X"), 0, Input.getaxis ("Mouse Y")); }} private bool Mousescreen () {bool temp = false; Vector2 tempposition= input.mouseposition; if (tempposition.x <2 | | tempposition.x > screen.width-2) {temp = true; if (Tempposition.x < 2 | | tempposition.x > SCreen.width-2) {temp = true; } return temp; }
This allows the camera to drag, but there are two problems, only when the mouse moves to the edge of the screen instead of the edge of the current window, there is the mouse will be off the boundary.
Unity Learning--004: Lens Controller