zoukankan      html  css  js  c++  java
  • Unity3D摄像机尾随人物

    这里的镜头主要是从人物的背后尾随的。

    首先新建一个C#脚本,命名为MyFollow,然后把下面代码粘贴进去。保存:

    using UnityEngine;
    using System.Collections;
    
    public class MyFollow : MonoBehaviour
    {
    	public float distanceAway = 5;			// distance from the back of the craft
    	public float distanceUp = 2;			// distance above the craft
    	public float smooth = 3;				// how smooth the camera movement is
    	
    	private GameObject hovercraft;		// to store the hovercraft
    	private Vector3 targetPosition;		// the position the camera is trying to be in
    	
    	Transform follow;
    	
    	void Start(){
    		follow = GameObject.FindWithTag ("Player").transform;	
    	}
    	
    	void LateUpdate ()
    	{
    		// setting the target position to be the correct offset from the hovercraft
    		targetPosition = follow.position + Vector3.up * distanceUp - follow.forward * distanceAway;
    		
    		// making a smooth transition between it's current position and the position it wants to be in
    		transform.position = Vector3.Lerp(transform.position, targetPosition, Time.deltaTime * smooth);
    		
    		// make sure the camera is looking the right way!
    		transform.LookAt(follow);
    	}
    }

    接着把上面的这个脚本挂载到摄像机上。

    最后把你想尾随的人物的tag设为Player。

    执行游戏后,摄像机就能够从人物背后尾随人物了。

  • 相关阅读:
    ZOJ 3949 Edge to the Root( 树形dp)
    CCF201812-3 CIDR合并
    CF700E E. Cool Slogans
    BZOJ4552: [Tjoi2016&Heoi2016]排序
    BZOJ3238: [Ahoi2013]差异
    BZOJ4566: [Haoi2016]找相同字符
    Codeforces Global Round 1 A~F
    (HDU)1555-- How many days? (多少天)
    (HDU)1491-- Octorber 21st (校庆)
    (HDU)1465-- 不容易系列之一
  • 原文地址:https://www.cnblogs.com/slgkaifa/p/7076119.html
Copyright © 2011-2022 走看看