UNITY3D-RPG Project Study notes (v)

Source: Internet
Author: User

The pre-project realizes the role movement, now needs to complete the lens to follow and control.

First, the lens of the following

The idea is simple, first get the lens initial and character distance vector value, and then let the camera and the character to maintain the distance of the vector. The script is as follows:

NameSpace Followplayer

Private Transform player;

Private Vector3 offsetposition;

void Start ()

{

Player = Gameoject.findgameobjectwithtag ("Player"). Transform;

Offsetposition = transform.position-player.position;

}

Void Update ()

{

Transform.position = player.position + offsetposition;

}

This allows the lens to follow the character movement effect.

Second, the lens control

The control of the lens is decomposed into the lens stretching and rotating.

2.1 Stretching of the lens

The tensile nature of the lens is to change the vector difference between the characters, and after the script takes effect, the vector difference of the lens to the character is Offsetposition, and is a fixed value, so now it is necessary to change the fixed value according to the operation.

Use Input.getaxis ("Mouse Scrollwheel") to record this value.

The above script is updated to:

NameSpace Followplayer

public float scrollspeed = 5;

void Srollview ()

{

float distance = offsetposition.magnitude; But the vector variance of the offsetposition.

Distance + = Input.getaxis ("Mouse scrollwheel"); Change the vector variance value according to the middle mouse button

Offsetposition = offsetposition.normalized * distance; Change the vector to a standard vector and multiply the variance to the target distance

}

Called in void Upadate () is available.

UNITY3D-RPG Project Study notes (v)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.