方法一:改变物体的transform public class ExampleClass : MonoBehaviour { ; // 跟随摄像机的移动要写在LateUpdate中 void LateUpdate() { transform.Translate(, , Time.deltaTime * speed); } } 方法二:使用刚体的位移函数MovePosition() public class ExampleClass : MonoBehaviour { public float s
这里假设在水中的船,船有惯性,在不添加前进动力的情况下会继续移动,但是船身是可以360度自由旋转,当船的运动速度在船的前方的时候,相机会根据向前的速度的大小,设置相机的偏移量,从而提高游戏的动态带感. 但是由于惯性船的速度不一定在船的,因此可以获得当前船的速度方向在船的前方的投影分量,当分量与船的前方同向,那么设置偏移量为:速度分量的长度与船的最大比值t,乘以相机设定的最大偏移量 代码1 如下 using System.Collections; using System.Collections.
固定相机跟随 这种相机有一个参考对象,它会保持与该参考对象固定的位置,跟随改参考对象发生移动 using UnityEngine; using System.Collections; public class CameraFlow : MonoBehaviour { public Transform target; private Vector3 offset; // Use this for initialization void Start() { offset = target.posit
方式一:将摄像机直接拖到游戏对象的下面: 方式二:脚本实现 using System.Collections; using System.Collections.Generic; using UnityEngine; public class kow : MonoBehaviour { public Transform targetTr; public float dist = 10.0F; public float height = 3.0F; public float dampTrace =