Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- {
- //Angle output of the goniometer calculation
- private float Calculated_angle;
- //The "resting" point of the tracker, allows the tracker to operate from any given starting point
- private float verticalneutralpoint; //Y-axis
- private float horizontalneutralpoint; //X-axis
- //the length of distance from the tracker to the pivot point being measured (in meters)
- public float Pivotlength = 0.49f; //Obligatory value used in testing
- public GameObject Tracker; //The tracker object
- void Update () {
- //Sets the neutral position of the tracker, converting from worldspace units to the real-world 0 point
- if (Input.GetKeyDown(KeyCode.Space) == true) {
- verticalneutralpoint = Tracker.transform.position.y;
- horizontalneutralpoint = Tracker.transform.position.x;
- }
- //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
- Calculated_angle = Mathf.Atan((Tracker.transform.position.y - verticalneutralpoint) / (Pivotength + (Tracker.transform.position.x - horizontalneutralpoint))) * Mathf.Rad2Deg;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement