Hello, I’m trying to convert a 2008 engine character controller to Unity3D, but I’m having some problems with those trigonometric functions, Sin and Cos:
float flDeltaCos = Mathf.Cos(flAnimDirection-90);
float flDeltaSin = Mathf.Sin(flAnimDirection-90);
Then If my speed length is greater or equal than 0.1:
flAnimDirection = Mathf.Atan2((vAcceleration.x+flDeltaCos*flSpeed_Length*6f),-(vAcceleration.z+flDeltaSin*flSpeed_Length*6f));
That’s the original unchanged code, Acceleration is always relative to the camera, so If I press W or the Up directional It will accelerate on the camera’s facing direction.
The original engine uses Euler angles I guess (0 to 360), The values are just changing really fast, They were supposed to slowly change relative to my acceleration, I also tried multiplying Atan2 results for Mathf.Rad2Deg but the character just spins uncontrollably.
flDeltaCos and flDeltaSin are also used for the ‘turning’ speed compensation which looks like:
vSpeedCompensation.x = (vSpeed.x*11f+flDeltaCos*flSpeed_Length)/12f;
vSpeedCompensation.z = (vSpeed.z*11f+flDeltaSin*flSpeed_Length)/12f;
Thanks!