Unity3d Camera Follow people

Source: Internet
Author: User

The lenses here are mainly from behind the characters.

Start by creating a new C # script named Myfollow, and then paste the following code in to save:

Using unityengine;using system.collections;public class myfollow:monobehaviour{public Float Distanceaway = 5;//Distanc E from the back of the craftpublic float distanceup = 2;//distance above the craftpublic float smooth = 3;//how smooth t He camera movement IsPrivate Gameobject hovercraft;//to store the hovercraftprivate Vector3 targetposition;//the Positio n the camera is trying to be intransform follow;void Start () {follow = Gameobject.findwithtag ("Player"). Transform;} void Lateupdate () {//Setting the target position to being the correct offset from the Hovercrafttargetposition = Follow.posi  tion + vector3.up * Distanceup-follow.forward * distanceaway;//making a smooth transition between it ' s current position And the position it wants to be intransform.position = Vector3.lerp (transform.position, targetposition, Time.deltatime * Smooth)//Make sure the camera was looking the right way!transform. LookAt (Follow);}}

Then attach the above script to the camera.

Finally, set the tag of the character you want to follow to the player.

After running the game, the camera can follow the character behind the character.

Unity3d Camera Follow people

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.