在一行对象中使用三角法动画波

时间:2016-08-08 09:03:18

标签: signal-processing trigonometry waveform

我有一排物体,我想突出显示/动画为单个波,偶然通过,然后所有物体变平

______¸,ø¤º°`°º¤,_________ ____________________________

不幸的是,我完全失败了,尽管有功能的视觉反馈,它完全失控。请给我一些建议。这是我在unityscript中失败的尝试,类似于AS:

function Update () {

    if (Input.GetKeyDown("b")) animating = !animating;
    if (animating ==true){
        for (movebat in movebats) //process every battery component
            { 
                var vy = movebat.transform.position.y*0.4 + Time.time*3;
                if ( vy % (Mathf.PI*4)>= (Mathf.PI)) 
                    vy = 0;
                movebat.transform.position.z  = Mathf.Sin(vy*.41+Time.time*3);
            }
    }
}

也许有一个钟形曲线函数或迭代技巧会更容易,对我来说是新的吗?

1 个答案:

答案 0 :(得分:0)

这是一个有效的代码版本:

function Update () {

    if (Input.GetKeyDown("b")) animating = !animating;
    if (animating ==true){
        for (movebat in movebats) 
            if( movebat!=null){ 
var vy = (movebat.transform.position.y*0.4+Time.time*3)% (Mathf.PI*8);
            if ( vy >= (Mathf.PI)) 
              vy = 0;
            movebat.transform.position.z  =
            -Mathf.Clamp(Mathf.Sin(vy ),0,1)*2;}
    }
}