椭圆

using UnityEngine;
using System.Collections;
using UnityEngine.Networking;

public class EllipseMove : NetworkBehaviour
{

    public float w;//椭圆长  
    public float h; //椭圆高  
    public float moveSpeed;
    public Vector3 prePos;


    public float temp_angle;

    private Vector3 _pos_new;

    public Vector3 _center_pos;

    public bool _round_its_center;

    void Start()
    {
        if (_round_its_center)
        {
            _center_pos = transform.localPosition;
        }
        InvokeRepeating("TransformPosition", 5, 5);
    }

    void Update()
    {

        _pos_new.x = _center_pos.x + (w * Mathf.Cos(moveSpeed * Time.time * Mathf.Deg2Rad));
        _pos_new.z = _center_pos.z + (h * Mathf.Sin(moveSpeed * Time.time * Mathf.Deg2Rad));
        _pos_new.y = transform.localPosition.y;

        transform.localPosition = _pos_new;
        Vector3 rotateVector = _pos_new - prePos;
        Quaternion newRotation = Quaternion.LookRotation(rotateVector);
        transform.rotation = Quaternion.RotateTowards(transform.rotation, newRotation, moveSpeed * Time.time);

        prePos = _pos_new;


    }

    private void TransformPosition()
    {
        GetComponent<NetworkTransform>().enabled = true;
        GetComponent<NetworkTransform>().enabled = false;
    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值