You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.3 KiB
50 lines
1.3 KiB
3 years ago
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
|
||
|
public class CaculateEularEngle : MonoBehaviour {
|
||
|
public GameObject self_;
|
||
|
public GameObject otherHand;
|
||
|
private Vector3 eularEngle;
|
||
|
|
||
|
// Use this for initialization
|
||
|
void Start () {
|
||
|
|
||
|
}
|
||
|
|
||
|
// Update is called once per frame
|
||
|
void Update () {
|
||
|
eularEngle = caculateEularEngle();
|
||
|
otherHand.transform.localEulerAngles = eularEngle;
|
||
|
}
|
||
|
|
||
|
Vector3 caculateEularEngle()
|
||
|
{
|
||
|
float x = self_.transform.position.x - otherHand.transform.position.x;
|
||
|
float y = self_.transform.position.y - otherHand.transform.position.y;
|
||
|
float z = self_.transform.position.z - otherHand.transform.position.z;
|
||
|
float engleX = 0.0f;
|
||
|
float engleY = 0.0f;
|
||
|
//float engleZ = 0.0f;
|
||
|
if (x >= 0f)
|
||
|
{
|
||
|
engleY = -Mathf.Atan(z / x) * 180f / Mathf.PI - 90f;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
engleY = 180.0f - Mathf.Atan(z / x) * 180f / Mathf.PI - 90f;
|
||
|
}
|
||
|
if (z >= 0f)
|
||
|
{
|
||
|
engleX = Mathf.Atan(y / z) * 180f / Mathf.PI;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
engleX = -Mathf.Atan(y / z) * 180f / Mathf.PI;
|
||
|
}
|
||
|
//engleZ = leftHand.transform.eulerAngles.z;
|
||
|
Vector3 eularEngle = new Vector3(-engleX, engleY + 180f, 0.0f);
|
||
|
return eularEngle;
|
||
|
}
|
||
|
}
|