123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class EllipticalOrbit : MonoBehaviour
- {
- [Tooltip("要移动的物体")]
- public GameObject go;
- [Tooltip("长轴长")]
- public float Ellipse_a;
- [Tooltip("短轴长")]
- public float Ellipse_b;
- [Tooltip("角度")]
- float angle;
- [Tooltip("半径")]
- public float Circular_R;
- [Tooltip("原点")]
- public GameObject Point;
- public GameObject cube;
- public float checkTargetDirForMe(Transform target)
- {
-
- Vector3 dir = target.position - transform.position;
-
-
- float dot = Vector3.Dot(transform.forward, dir.normalized);
- float dot1 = Vector3.Dot(transform.right, dir.normalized);
- float angle = Mathf.Acos(Vector3.Dot(transform.forward.normalized, dir.normalized)) * Mathf.Rad2Deg;
-
-
- Vector3 cross = Vector3.Cross(transform.forward, dir.normalized);
- Vector3 cross1 = Vector3.Cross(transform.right, dir.normalized);
- angle = Mathf.Asin(Vector3.Distance(Vector3.zero, Vector3.Cross(transform.forward.normalized, dir.normalized))) * Mathf.Rad2Deg;
- return angle;
- }
- private void Update()
- {
-
- angle = checkTargetDirForMe(cube.transform)/90;
-
-
-
-
- Move(Ellipse_X(Ellipse_a, angle), Ellipse_Y(Ellipse_b, angle));
- }
-
-
-
-
-
- private void Move(float x, float y)
- {
- go.transform.position = new Vector3(x + Point.transform.position.x, 0, y + Point.transform.position.z);
- }
-
-
-
-
-
-
- private float Ellipse_X(float a, float angle)
- {
- return a * Mathf.Cos(angle * Mathf.Rad2Deg);
- }
-
-
-
-
-
-
- private float Ellipse_Y(float b, float angle)
- {
- return b * Mathf.Sin(angle * Mathf.Rad2Deg);
- }
-
- private void Dot()
- {
-
-
- Vector3 a = new Vector3(1, 1, 1);
- Vector3 b = new Vector3(1, 5, 1);
-
- float result = Vector3.Dot(a, b);
-
- float angle = Vector3.Angle(a, b);
-
-
-
- result = Vector3.Dot(a.normalized, b.normalized);
-
- float radians = Mathf.Acos(result);
-
- angle = radians * Mathf.Rad2Deg;
- }
-
- private void Cross()
- {
-
-
- Vector3 a = new Vector3(1, 1, 1);
- Vector3 b = new Vector3(1, 5, 1);
-
- Vector3 c = Vector3.Cross(a, b);
-
-
- float radians = Mathf.Asin(Vector3.Distance(Vector3.zero, Vector3.Cross(a.normalized, b.normalized)));
- float angle = radians * Mathf.Rad2Deg;
-
-
-
- if (c.y > 0)
- {
-
- }
- else if (c.y == 0)
- {
-
- }
- else
- {
-
- }
- }
-
-
-
- private void GetAngle(Vector3 a, Vector3 b)
- {
- Vector3 c = Vector3.Cross(a, b);
- float angle = Vector3.Angle(a, b);
-
- float sign = Mathf.Sign(Vector3.Dot(c.normalized, Vector3.Cross(a.normalized, b.normalized)));
- float signed_angle = angle * sign;
- Debug.Log("b -> a :" + signed_angle);
-
- sign = Mathf.Sign(Vector3.Dot(c.normalized, Vector3.Cross(b.normalized, a.normalized)));
- signed_angle = angle * sign;
- Debug.Log("a -> b :" + signed_angle);
- }
- }
|