互联网第一工具箱,让工作变得更为简单!
  • 955阅读
  • 1回复

[易语言开发] 关于unity 第一人称与第三人称写法总结


会员


发帖
46
楼主  发表于:2020/8/11 9:03

今天学了摄像机跟随 总觉得网上得方法不是太直接 自己总结写了一种写法 分享给大家

public class camera_follow : MonoBehaviour

{

    public Transform target;

    private Vector3 offset;

    // Start is called before the first frame update

    void Start()

    {

        offset = this.transform.position - target.position;

    }


    // Update is called once per frame

    void Update()

    {

        //第三人称呼写法

        this.transform.position = offset + target.position;


        //第一人称呼写法

        this.transform.position = this.target.position - this.target.forward * 6 + this.target.up * 2;

        this.transform.LookAt(this.target);




    }

}



                    
会员


发帖
楼主   发表于: 2020年10月31日 9:33

另外一种第三人称写法如下


    void usermove(float dt)
{
if (this.move_x == 0 && this.move_y == 0) {
return;
}
BinDebug.Log("move_x:" + this.move_x + ";move_y:" + this.move_y);
//float dir_x = ((float)this.move_x / (float)(1 << 16));
//float dir_y = ((float)this.move_y / (float)(1 << 16));
float dir_x = this.move_x >0 ?1:this.move_x==0?0:-1;
float dir_y = this.move_y>0?1:this.move_y==0?0:-1;
float r = Mathf.Atan2(dir_y, dir_x);

float s = this.speed * dt;
float sx = s * Mathf.Cos(r);
float sz = s * Mathf.Sin(r);
this.transform.Translate(new Vector3(sx, 0, sz), Space.Self);
}


快速回复