2020-11-04

  //旋转速度
    float RevolutionSpeed = 20f;

    //中心点
    public Transform RevolutionTarget;

    //点所在的角度
    public float _Angle = 0;

    //X,y,z轴的位置偏移
    public float XDeviation;
    public float YDeviation;
    public float ZDeviation;
    //半径
    public float _radius;

    //x,y,z轴的膨胀偏移
    public float XRotateSpeed;
    public float YRotateSpeed;
    public float ZRotateSpeed;

    //上面出的是一个平面的圆,加上这个圆或者椭圆即会倾斜
    public float An;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        //自我旋转
       _Angle += RevolutionSpeed * Time.deltaTime;
        if (_Angle > 360) _Angle -= 360;

        //椭圆算法
        float x = RevolutionTarget.position.x + XDeviation + Mathf.Cos(_Angle * (Mathf.PI / 180)) * _radius * XRotateSpeed;
        float y = RevolutionTarget.position.y + YDeviation + Mathf.Sin(_Angle * (Mathf.PI / 180)) * _radius * YRotateSpeed;
        float z = RevolutionTarget.position.z + ZDeviation + Mathf.Sin(_Angle * (Mathf.PI / 180)) * _radius * ZRotateSpeed;
        //椭圆算法的基础上添加倾斜算法,如无需倾斜注释掉下面两行代码
        x = x * Mathf.Cos(An) + y * Mathf.Sin(An);
        y = x * -Mathf.Sin(An) + y * Mathf.Cos(An);
        transform.position = new Vector3(x, y, z);

       
        //此时图片在后方,物体越后面,物体越来越小,且越来越暗淡,这个判断值需要比较圆形图片在最左最右时的位置,
        //这里根据我的需求,通过判断Y值,判定图片在后方还是前方
        if (transform.localPosition.y > 145)
        {
            float posy = transform.localPosition.y;
            float s = 1f - (0.5f * (posy / 200f));
            transform.localScale = new Vector3(s, s, 1f);
          //  transform.GetComponent<Image>().color = new Color(255f, 255f, 255f, s);
        }
        //此时图片在前方,物体越前面,越来越大,越来越亮
        if (transform.localPosition.y <155)
        {
            float posy = transform.localPosition.y;

            float s = 1f - (0.5f * (posy / 200f));
            transform.localScale = new Vector3(s, s, 1f);
            //transform.GetComponent<Image>().color = new Color(255f, 255f, 255f, s);
        }
    

    }

    private void OnDrawGizmos()
    {


        // 绘制目标线
        Gizmos.color = Color.red;
        Gizmos.DrawLine(RevolutionTarget.position, transform.position);

        // 绘制轨道
        Gizmos.color = Color.blue;
        float sub = 0.1f;
        float i = 0;
        // 轨道起点
        float x = RevolutionTarget.position.x + XDeviation + _radius * Mathf.Cos(i) * XRotateSpeed;
        float y = RevolutionTarget.position.y + YDeviation + _radius * Mathf.Sin(i) * YRotateSpeed;
        float z = RevolutionTarget.position.z + ZDeviation + _radius * Mathf.Sin(i) * ZRotateSpeed;
        x = x * Mathf.Cos(An) + y * Mathf.Sin(An);
        y = x * -Mathf.Sin(An) + y * Mathf.Cos(An);
        Vector3 sPoint = new Vector3(x, y, z);
        Vector3 ePoint = Vector3.zero;
        for (i += sub; i <= Mathf.PI * 2; i += sub)
        {
            x = RevolutionTarget.position.x + XDeviation + _radius * Mathf.Cos(i) * XRotateSpeed;
            y = RevolutionTarget.position.y + YDeviation + _radius * Mathf.Sin(i) * YRotateSpeed;
            z = RevolutionTarget.position.z + ZDeviation + _radius * Mathf.Sin(i) * ZRotateSpeed;
            x = x * Mathf.Cos(An) + y * Mathf.Sin(An);
            y = x * -Mathf.Sin(An) + y * Mathf.Cos(An);
            ePoint = new Vector3(x, y, z);
            Gizmos.DrawLine(sPoint, ePoint);
            sPoint = ePoint;
        }
        // 轨道终点
        x = RevolutionTarget.position.x + XDeviation + _radius * Mathf.Cos(Mathf.PI * 2) * XRotateSpeed;
        y = RevolutionTarget.position.y + YDeviation + _radius * Mathf.Sin(Mathf.PI * 2) * YRotateSpeed;
        z = RevolutionTarget.position.z + ZDeviation + _radius * Mathf.Sin(Mathf.PI * 2) * ZRotateSpeed;
        x = x * Mathf.Cos(An) + y * Mathf.Sin(An);
        y = x * -Mathf.Sin(An) + y * Mathf.Cos(An);
        ePoint = new Vector3(x, y, z);
        Gizmos.DrawLine(sPoint, ePoint);
    }

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值