实现物体绕不同轴旋转,并可以外部调用的函数

该博客介绍了如何在Unity3D中实现物体围绕不同轴的旋转,包括均匀旋转和加速旋转两种方式。通过定义枚举类型`CTRotationType`区分旋转类型,提供`RotateTo`函数供外部调用,设定旋转角度、轴向、持续时间和加速度。测试脚本展示了如何在游戏运行时触发这两种旋转方式。
摘要由CSDN通过智能技术生成

第一个文件,声明枚举类型,分别为均匀变化和加速变化

using UnityEngine;
using System.Collections;

public enum CTRotationType
{
    Uniform,
    AccelerateUniformly
}

 

第二个文件:主函数,实现围绕轴变化的两个函数,分别为均匀变化和加速变化

 using UnityEngine;
using System.Collections;

public class CTRotation : MonoBehaviour {

 // Use this for initialization
 void Start () {
 
 }
 
 // Update is called once per frame
 void Update () {
        if (isRotating)
        {
            executeRotate();
        }
    }

    bool isRotating = false;

    Quaternion definedRotation = new Quaternion(0, 0, 0,0);
 
    Vector3 rotateVector = new Vector3(1,0,0);
 
    float rotateVelocity = 0;
 
 float accelerateDuration = 0;
 float leftDuration = 0;
 float rotateDuration = 0;
 
    int rotateAxis = 0;
 float angleRange = 0;
 float deltaRotate = 0;//0;
 
 
 // acceleration when it is in the accelerating process.
    float rotateAcceleration = 0;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值