Unity3D開發之計算向量角度的方式

//計算夾角的角度 0~360
	float angle_360(Vector3 from_, Vector3 to_){
		Vector3 v3 = Vector3.Cross(from_,to_);
		if(v3.z > 0)
			return Vector3.Angle(from_,to_);
		else
			return 360-Vector3.Angle(from_,to_);
	}

調用如下:

angle = angle_360(new Vector3(0,-1,0),transform.position);	
可以獲取得到與向下夾角的角度值。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章