I am using this code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HARcieveAngleChanger : MonoBehaviour
{
private float ha;
private float HAZ;
public ConfigurableJoint CJ;
public Vector3 newanchor;
public Vector3 newaxis;
public void OnValueChangedHA(float newValue)
{
ha = (HAGrab.HAUpdate);
UnityEngine.Debug.Log("ha WHAT YO DOING = " + ha);
HAZ =(float)0.8 * (Mathf.Tan(ha)) ;
UnityEngine.Debug.Log("HAZ WHAT YO DOING = " + HAZ);
transform.position = new Vector3(0,0, HAZ);
newanchor.y = (float)-8;
newanchor.z = -HAZ;
newaxis.y = (float)8;
newaxis.z = HAZ;
CJ.connectedAnchor = newanchor;
CJ.secondaryAxis = newaxis;
}
}
From the debug.log(ha)
, I am getting 45 when I enter a 45 value into the input UI. The HAGrab
code gets this. However, the value outputted for HAZ
always comes out incorrect (i.e. using trig TOA, tan(angle)*length
of alternate side = opposite side, with a 45 degree angle it should come out as 0.8)...
Does anyone have any ideas for why this is the case?
Mathf.Deg2Rad
, since trig functions take their input in radians? \$\endgroup\$ha
variable needs to be in radians. see here. I'm not sure what you are trying to accomplish here, but you will not get the correct calculations using angles here. Convert the angles to radians first, and try to identify the next problem \$\endgroup\$