Unity(十九) Mathf.SmoothDamp平滑運動 Mathf.MoveTowards、Mathf.Lerp

 public Transform target;        
    public float smoothTime = 1f;  
    private Vector3 velocity;       
    void Update()
    {
        //Set the position
        transform.position 
            = new Vector3(
                Mathf.SmoothDamp(transform.position.x, target.position.x, ref velocity.x, smoothTime), 
                Mathf.SmoothDamp(transform.position.y, target.position.y, ref velocity.y, smoothTime),
                 Mathf.SmoothDamp(transform.position.z, target.position.z, ref velocity.z, smoothTime)
                );
    }

// float result=Mathf.MoveTorwards(float current,float target,float delta);
float delta=10f;
void FixedUpdate()
{

   float result=Mathf.MoveTorwards(current,target,Time.fixedDeltaTime*delta);

}


//如汽車動力的提升

//float result=Mathf.Lerp(float current,float target,float percent)
void FixedUpdate()
{

    float result=Mathf.Lerp(float current,float target,float percent)
}

//如汽車油門的輸入,離合的輸入。percent爲百分比範圍=[0,1]
//如0--100,percent=0.1,則result=target=10

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章