void move(){
//distance Calc
transform.position = new Vector3( transform.position.x,
playerAttachedPoint.transform.position.y+fixed_yDist,transform.position.z);
xDis = playerAttachedPoint.transform.position.x - transform.position.x;
zDis = playerAttachedPoint.transform.position.z - transform.position.z;
totDis = Mathf.Sqrt(Mathf.Pow(xDis,2)+Mathf.Pow(zDis,2));
//set camera velocity
GetComponent<Rigidbody>().velocity = new Vector3
(
Mathf.Clamp(playerController.vectoredim2magnitude(playerController.velocity),maxSpeed,playerController.vectoredim2magnitude(playerController.velocity))
* Mathf.Abs(xDis/totDis) * Mathf.Sin(Mathf.Clamp(xDis/maxDisplacement/2f*Mathf.PI,-Mathf.PI/2,Mathf.PI/2)) ,
0f,Mathf.Clamp(playerController.vectoredim2magnitude(playerController.velocity),maxSpeed,playerController.vectoredim2magnitude(playerController.velocity))
* Mathf.Abs(zDis/totDis) * Mathf.Sin(Mathf.Clamp(zDis/maxDisplacement/2f*Mathf.PI,-Mathf.PI/2,Mathf.PI/2)));
}
如果有興趣的話不仿也動手做做看喔,我也準備了一些其他類型的函數,如果想試試其他的效果也可以拿來玩玩看!