小编Aru*_*n K的帖子

相机每隔几秒跟随背景对象的 Rigidbody 抖动一次

相机跟随 Rigidbody2D 每隔几秒抖动一次背景(非刚体)对象(障碍物)。Profiler 中的 FPS 很好,接近 100。插值也很好。使用Unity 2017.4.12(LTS)

GIF GIF 视频在这里

相机跟随脚本

 public class CameraFollow : MonoBehaviour {
        public float followRange = 0.5f;
        public float cameraZ;
        public Transform Player;
        public Vector3 newPos;
        void Start () {
            cameraZ = transform.position.z;
        }
        void FixedUpdate() {
            newPos = new Vector3(Player.position.x + followRange, 0, cameraZ);
            transform.position = Vector3.Lerp(transform.position, newPos, 0.5f);
        }   
    }
Run Code Online (Sandbox Code Playgroud)

播放器脚本:

public class PlayerBall : MonoBehaviour {

    public float xSpeed = 10;

    // Update is called once per frame
    void FixedUpdate () …
Run Code Online (Sandbox Code Playgroud)

c# unity-game-engine game-physics unity3d-2dtools

1
推荐指数
1
解决办法
6084
查看次数