moba类游戏开发日志(四)自定义相机视角的实现
测试过程中一直看着角色的背,总感觉有些不对劲,想来还是camera tracking的问题,于是自己写了个camera controller挂在了自定义的一个maincamera上
嗯,代码没几行,其实就是逐帧检测角色位置让后让相机挪到对应的相对位置,如果有其他需求后续也可以在上面加
using System.Collections; using System.Collections.Generic; using UnityEngine; public class CameraFollow : MonoBehaviour { [SerializeField] private Transform player; float cameraX; float cameraZ; public float y = 10; public float z = 5; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { if(player) { cameraX = player.position.x; cameraZ = player.position.z; this.transform.position = new Vector3(cameraX,y,cameraZ+z); } } }
发表评论