Self-taught Unity3d snake add camera follow

Source: Internet
Author: User

In Unity's world, the positions of objects are made up of vectors.

What needs to be done today is to keep the camera at a relative distance from the head of the snake.

First, position the snake head at point A, the camera's position at point B.

Then we can know their offset = b-a;

So the new camera position should be B = A + offset;

Make: The motion of the camera is moving according to the frame so it is jitter, we should do a smoothing process

The exact vector gives us a way to use interpolation to move smoothly

Vector3.lerp (B,a + offset,0.1f) That means smooth moving to the middle of the interpolation

Mathf.lerp

static function Lerp (From:float, To:float, t:float): float

Returns the interpolation between A and b based on the floating-point number T, which is limited to 0~1. When t = 0 returns from, when t = 1 returns to. When t = 0.5 returns the mean of the From and to.

Color.lerp

static function Lerp (A:color, B:color, t:float): Color

Interpolates between Colors A and B by T.

"T" is a value sandwiched between 0 and 1. When T is 0 o'clock returns the color A. When T is 1 o'clock returns the color B.

To see the interpolation calculation of Unity in detail

Self-taught Unity3d snake add camera follow

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.