gesture relative to player
This commit is contained in:
@@ -14,6 +14,8 @@ public class GestureRecognizer : MonoBehaviour
|
||||
public InputHelpers.Button rightInputButton;
|
||||
public InputHelpers.Button rightControlButton;
|
||||
|
||||
public Camera mainCamera;
|
||||
|
||||
public float inputThreshold = 0.1f;
|
||||
public Transform movementSource;
|
||||
|
||||
@@ -31,10 +33,15 @@ public class GestureRecognizer : MonoBehaviour
|
||||
private List<Gesture> trainingSet = new List<Gesture>();
|
||||
private bool isMoving = false;
|
||||
private List<Vector3> positionsList = new List<Vector3>();
|
||||
private Vector3 relativePosition;
|
||||
private List<GameObject> debugCubes;
|
||||
private List<Vector3> relativePositions;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
debugCubes = new List<GameObject>();
|
||||
relativePositions = new List<Vector3>();
|
||||
// Path = ..\AppData\LocalLow\DefaultCompany\Heroes of Hiis SCM
|
||||
Debug.Log(Application.persistentDataPath);
|
||||
string[] gestureFiles = Directory.GetFiles(Application.persistentDataPath, "*.xml");
|
||||
@@ -85,13 +92,18 @@ public class GestureRecognizer : MonoBehaviour
|
||||
|
||||
void StartMovement()
|
||||
{
|
||||
debugCubes.Clear();
|
||||
relativePositions.Clear();
|
||||
Debug.Log("Movement started");
|
||||
isMoving = true;
|
||||
positionsList.Clear();
|
||||
positionsList.Add(movementSource.position);
|
||||
relativePosition = movementSource.position - mainCamera.transform.position;
|
||||
positionsList.Add(relativePosition);
|
||||
if (debugCubePrefab)
|
||||
{
|
||||
Destroy(Instantiate(debugCubePrefab, movementSource.position, Quaternion.identity), 3);
|
||||
GameObject cube = Instantiate(debugCubePrefab, relativePosition, Quaternion.identity);
|
||||
debugCubes.Add(cube);
|
||||
relativePositions.Add(relativePosition);
|
||||
}
|
||||
}
|
||||
void EndMovement()
|
||||
@@ -129,17 +141,31 @@ public class GestureRecognizer : MonoBehaviour
|
||||
|
||||
}
|
||||
}
|
||||
foreach(GameObject obj in debugCubes)
|
||||
{
|
||||
Destroy(obj);
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateMovement()
|
||||
{
|
||||
Vector3 lastPosition = positionsList[positionsList.Count - 1];
|
||||
if (Vector3.Distance(movementSource.position, lastPosition) > newPositionThresholdDistance)
|
||||
relativePosition = movementSource.position - mainCamera.transform.position;
|
||||
|
||||
|
||||
for(int i = 0; i < debugCubes.Count; i++)
|
||||
{
|
||||
positionsList.Add(movementSource.position);
|
||||
debugCubes[i].transform.position = mainCamera.transform.position + relativePositions[i];
|
||||
}
|
||||
|
||||
Vector3 lastPosition = positionsList[positionsList.Count - 1];
|
||||
if (Vector3.Distance(relativePosition, lastPosition) > newPositionThresholdDistance)
|
||||
{
|
||||
positionsList.Add(relativePosition);
|
||||
if (debugCubePrefab)
|
||||
{
|
||||
Destroy(Instantiate(debugCubePrefab, movementSource.position, Quaternion.identity), 3);
|
||||
GameObject cube = Instantiate(debugCubePrefab, relativePosition, Quaternion.identity);
|
||||
debugCubes.Add(cube);
|
||||
relativePositions.Add(relativePosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user