Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. {
  6. //Angle output of the goniometer calculation
  7. private float Calculated_angle;
  8.  
  9. //The "resting" point of the tracker, allows the tracker to operate from any given starting point
  10. private float verticalneutralpoint; //Y-axis
  11. private float horizontalneutralpoint; //X-axis
  12.  
  13. //the length of distance from the tracker to the pivot point being measured (in meters)
  14. public float Pivotlength = 0.49f; //Obligatory value used in testing
  15.  
  16. public GameObject Tracker; //The tracker object
  17.  
  18. void Update () {
  19. //Sets the neutral position of the tracker, converting from worldspace units to the real-world 0 point
  20. if (Input.GetKeyDown(KeyCode.Space) == true) {
  21. verticalneutralpoint = Tracker.transform.position.y;
  22. horizontalneutralpoint = Tracker.transform.position.x;
  23. }
  24. //Calculates the angle, using the difference from the neutralpoints as the X and Y vectors, Pivotlength replaces the need for a second tracker to calculate distance from pivot
  25. Calculated_angle = Mathf.Atan((Tracker.transform.position.y - verticalneutralpoint) / (Pivotength + (Tracker.transform.position.x - horizontalneutralpoint))) * Mathf.Rad2Deg;
  26.  
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement