public class FollowCameraController : MonoBehaviour {
float distance = 5f ;
float distanceY = 2f ;
Transform target;
Transform myTransform;
float velocity = 0.1f;
float hevi = 0.5f;
// Use this for initialization
void Start () {
//playerModel = RootServer.instance.GetObject(ROOTObject.Player);
//targetPosition = playerModel.transform.position;
target = GameObject.Find("PlayerModel").transform;
myTransform = transform;
}
private void LateUpdate()
{
FollowTarget();
}
void FollowTarget()
{
//按y轴的旋转
float targetAngleY = target.eulerAngles.y;
float curAngle = myTransform.eulerAngles.y;
//旋转中间值
curAngle = Mathf.SmoothDampAngle(curAngle, targetAngleY, ref velocity, 0.5f);
float targetHight = target.position.y + distanceY;
float cameraHight = Mathf.SmoothDamp(myTransform.position.y, targetHight,ref hevi, 1f );
Quaternion currentRotation = Quaternion.Euler(0, curAngle, 0);
myTransform.position = target.transform.position;
myTransform.position += currentRotation * Vector3.back*distance;
myTransform.position = new Vector3(myTransform.position.x, cameraHight, myTransform.position.z);
SetRotation(target.position);
}
float AngleDitance(float a , float b )
{
a = Mathf.Repeat(a, 360);
b = Mathf.Repeat(b, 360);
return Mathf.Abs(b - a);
}
void SetRotation( Vector3 target )
{
Vector3 cameraPos = myTransform.position;
Vector3 horDir = target - cameraPos;
//摄像机朝向
Quaternion yRotate = Quaternion.LookRotation(new Vector3(horDir.x, 0, horDir.z));
Vector3 relativeOffset = Vector3.forward * distance + Vector3.down * distanceY;
myTransform.rotation = yRotate * Quaternion.LookRotation(relativeOffset);
}
void CameraShake( float intputX , float inputY )
{
}
}
实现摄像机跟随并旋转
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...