-
-
Notifications
You must be signed in to change notification settings - Fork 982
Expand file tree
/
Copy pathAzimuthCheck.cs
More file actions
81 lines (76 loc) · 2.43 KB
/
AzimuthCheck.cs
File metadata and controls
81 lines (76 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class AzimuthCheck : MonoBehaviour
{
public GameObject controller;
public static bool modifyAzimuth = false;
private float initLen = 0f;
private float initAzimuthAngle = 0f;
private float initAltitudeAngle = 0f;
private float curLen = 0f;
private float curAzimuthAngle = 0f;
private float curAltitudeAngle = 0f;
private float maxAzimuthLen = 0f;
// Start is called before the first frame update
void Start()
{
if (controller == null) {
controller = GameObject.FindGameObjectWithTag("Controller");
}
initLen = controller.GetComponent<InputActionProperty>().action.GetBindingIndex();
initAzimuthAngle = gameObject.transform.rotation.x;
initAltitudeAngle = gameObject.transform.rotation.z;
maxAzimuthLen = initLen;
}
// Update is called once per frame
void Update()
{
curAzimuthAngle = gameObject.transform.rotation.x;
curAltitudeAngle = gameObject.transform.rotation.z;
curLen = (float)Math.Cos(initLen * curAzimuthAngle) + (float)Math.Sin(initLen * curAltitudeAngle);
if (curLen == initLen) {
return;
}
if (curAzimuthAngle > initAzimuthAngle) {
if (curAltitudeAngle > initAltitudeAngle) {
modifyAzimuth = true;
}
else {
modifyAzimuth = false;
}
}
else {
if (curAltitudeAngle > initAltitudeAngle) {
modifyAzimuth = false;
}
else {
modifyAzimuth = true;
}
}
if (curAltitudeAngle > initAltitudeAngle) {
if (curAzimuthAngle > initAzimuthAngle) {
modifyAzimuth = false;
}
else {
modifyAzimuth = true;
}
}
else {
if (curAzimuthAngle > initAzimuthAngle) {
modifyAzimuth = true;
}
else {
modifyAzimuth = false;
}
}
}
void LateUpdate() {
if (modifyAzimuth) {
curLen /= (float)(Math.Sqrt(3) / 2);
}
controller.transform.position = new Vector3(controller.transform.position.x, controller.transform.position.y, controller.transform.position.z - curLen);
}
}