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);

        }
    }
  • 相关阅读:
    yii2 页面渲染方法解析
    JavaScript 编码小技巧
    Ansible Playbooks入门介绍
    CentOS 7 源码安装Ansible 2.x
    GitLab 安装与入门
    SpringBoot 悲观锁 与 乐观锁
    SpringBoot 事务隔离性和传播性
    SpringBoot 定义通过字段验证
    SpringBoot 密码MD5加密
    SpringBoot MockMVC
  • 原文地址:https://www.cnblogs.com/bandy/p/2409587.html
Copyright © 2011-2022 走看看