|
|
@@ -10,8 +10,8 @@ public class EyeLaser : MonoBehaviour
|
|
|
private GameObject end1, end2;
|
|
|
public Transform headPos;
|
|
|
public Transform endPos;
|
|
|
- public float deltaDis1, deltaDis2;
|
|
|
- public float maxX;
|
|
|
+ public float deltaAngle1, deltaAngle2;
|
|
|
+ public float lineLen;
|
|
|
|
|
|
[Header("ÌØÐ§")]
|
|
|
private bool hasPrepared;
|
|
|
@@ -135,29 +135,41 @@ public class EyeLaser : MonoBehaviour
|
|
|
col2.right = -left2;
|
|
|
}
|
|
|
|
|
|
+ //µãAÈÆµãBתºó×ø±ê
|
|
|
+ Vector2 RotatePointAroundPivot(Vector2 point, Vector2 pivot, float angleDegrees)
|
|
|
+ {
|
|
|
+ float angleRadians = angleDegrees * Mathf.Deg2Rad;
|
|
|
+ float dx = point.x - pivot.x;
|
|
|
+ float dy = point.y - pivot.y;
|
|
|
+ float cosTheta = Mathf.Cos(angleRadians);
|
|
|
+ float sinTheta = Mathf.Sin(angleRadians);
|
|
|
+ float newX = cosTheta * dx - sinTheta * dy;
|
|
|
+ float newY = sinTheta * dx + cosTheta * dy;
|
|
|
+ return new Vector2(pivot.x + newX, pivot.y + newY);
|
|
|
+ }
|
|
|
+
|
|
|
private Vector3 TranEnd(int id)
|
|
|
{
|
|
|
- Vector2 dis = endPos.position - headPos.position;
|
|
|
+ Vector3 pos = (endPos.position - headPos.position).normalized * lineLen + headPos.position;
|
|
|
+ pos.z = 0;
|
|
|
switch (id)
|
|
|
{
|
|
|
case 1:
|
|
|
- dis.x -= deltaDis1;
|
|
|
+ pos = RotatePointAroundPivot(pos, headPos.position, deltaAngle1);
|
|
|
break;
|
|
|
case 2:
|
|
|
- dis.x += deltaDis2;
|
|
|
+ pos = RotatePointAroundPivot(pos, headPos.position, deltaAngle2);
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
- float k = dis.x / dis.y;
|
|
|
- Vector3 en = endPos.position;
|
|
|
- en.x += (-2 - en.y) * k;
|
|
|
- if (en.x - headPos.position.x > maxX)
|
|
|
+ if (pos.y < -1)
|
|
|
{
|
|
|
- en.x = headPos.position.x + maxX;
|
|
|
+ float k = (headPos.position.y + 1) / (headPos.position.y - pos.y);
|
|
|
+ pos.x = k * (pos.x - headPos.position.x) + headPos.position.x;
|
|
|
+ pos.y = -1;
|
|
|
}
|
|
|
- en.y = -1;
|
|
|
- return en;
|
|
|
+ return pos;
|
|
|
}
|
|
|
|
|
|
private void Update()
|