mirror of
https://projects.caleb-brown.dev/UDRI-XRT/UDRIGEEKCup2024.git
synced 2025-01-22 15:18:25 -05:00
37 lines
967 B
C#
37 lines
967 B
C#
using System;
|
|
using UnityAtoms.BaseAtoms;
|
|
using UnityEngine;
|
|
|
|
namespace GolfControls
|
|
{
|
|
public class AngleCalculator : MonoBehaviour
|
|
{
|
|
public Vector3Variable directionVariable;
|
|
public FloatVariable angleVariable;
|
|
|
|
public Transform targetTransform;
|
|
|
|
|
|
private void Update()
|
|
{
|
|
Vector3 myPos = transform.position;
|
|
Vector3 targetPos = targetTransform.position;
|
|
|
|
Vector3 angleVector = Vector3.ProjectOnPlane(myPos - targetPos,Vector3.down);
|
|
|
|
directionVariable.SetValue(angleVector);
|
|
|
|
double angle = getAngle(Vector2.zero, new Vector2(angleVector.z, angleVector.x));
|
|
|
|
float adjustedAngle = (float) angle + 180.0f;
|
|
|
|
angleVariable.SetValue(adjustedAngle);
|
|
|
|
double getAngle(Vector2 me, Vector2 target) {
|
|
return Math.Atan2(target.y - me.y, target.x - me.x) * (180/Math.PI);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|