unity物体围绕圆周运动,如圆环起始点做圆周运动

有个需求是做一个圆环,圆环前有个起始点跟随圆环移动。圆环很简单,把图片类型设置为Filled  360度的,方向为Right,做个Dotween动画,圆环就可以动起来了。如图圆环设置

 

圆环上的起始点做法。

给定一个圆长度,速度,中心点就可以旋转了。上代码:

 

using UnityEngine;
using System.Collections;
 
public class RoundAction : MonoBehaviour
{
    public float _radius_length;
    public float _angle_speed;
 
    private float temp_angle;
 
    private Vector3 _pos_new;
 
    public Vector3 _center_pos;
 
    public bool _round_its_center;
 
    // Use this for initialization
    void Start()
    {
        if (_round_its_center)
        {
            _center_pos = transform.localPosition;
        }
    }
 
    // Update is called once per frame
    void Update()
    {
        temp_angle += _angle_speed * Time.deltaTime; // 
 
        _pos_new.x = _center_pos.x + Mathf.Cos(temp_angle) * _radius_length;
        _pos_new.y = _center_pos.y + Mathf.Sin(temp_angle) * _radius_length;
        _pos_new.z = transform.localPosition.z;
 
        transform.localPosition = _pos_new;
    }
}

 

  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值