zoukankan      html  css  js  c++  java
  • Cube翻滚前进

    方法一:给Cube添加rigidbody,然后代码rigidbody.AddTorque (10, 0, 0);将使Cube沿X轴翻滚

    方法二:Cube没有 添加rigidbody,利用以下代码计算翻滚

    // Reposting this non-working answer because it was unreadable when posted as a comment to the previous answer

    var cubeSize : float = 1; 
    var cubeSpeed : float = 80;

    private var totalRotation : float = 0; // determines if we're past the 90 degrees
    private var startHeight : float = 0; // for correcting height errors

    // next two vars are for determining the corner
    //
     to rotate over
    private var fwdWeight : float = 0.5;
    private var upWeight : float = -0.5; 


    // Use this for initialization
    function Start () {
        startHeight = transform.position.y;
    }

    // Update is called once per frame
    function Update () {

        DoRoll(2);

    }

    function DoRoll (delay: float) {
        var spinAmount : float = Time.deltaTime * cubeSpeed;
        var t : float;
        var pos : Vector3;

        // we rotate around one of the edges of the cube (the stationary one of course)
        transform.RotateAround(transform.position + (fwdWeight * transform.forward + upWeight * transform.up) * cubeSize, Vector3.right, spinAmount);

        // add to amount of spin in this update the total rotation
        totalRotation += spinAmount;

        // check if we have to move to the next edge
        if (totalRotation >= 90) {
                // we move to next corner as pivot point
                totalRotation -= 90;
                t = fwdWeight;
                fwdWeight = -upWeight;
                upWeight = t;

                // make sure height stays correct
                pos = transform.position;
                pos.y = startHeight;
                transform.position = pos;
                print ("At rotation " + totalRotation);
                yield WaitForSeconds(delay);

        }
    }
  • 相关阅读:
    c语言面试基础题
    fwrite(&stud[i],sizeof(struct student_type),1,fp)的基本含义
    对于文件操作函数的记录
    将字符串s1复制到字符串s2。
    将键盘输入的几个数据存储到文件里的程序
    利用指针对二维数组进行遍历查找程序
    常见的C语言错误及程序的调试
    文件的基本操作函数及说明
    一个磁盘信息向另一个磁盘信息的复制
    常用流程图符号和基本流程图
  • 原文地址:https://www.cnblogs.com/bandy/p/2409587.html
Copyright © 2011-2022 走看看