In my previous threads I have discussed with people on how I can make directional sprites but nothing works except for this code
int GetAngleIndex()
{
var dir = GetComponent<Camera>().transform.position - transform.parent.forward;
var enemyAngle = Mathf.Atan2(dir.z, dir.x) * Mathf.Rad2Deg;
if (enemyAngle < 0.0f)
enemyAngle += 360;
Debug.Log("Angle from the player is: " + enemyAngle);
if (enemyAngle >= 292.5f && enemyAngle < 337.5f)
zom.SetFloat("rotation",0);
else if (enemyAngle >= 22.5f && enemyAngle < 67.5f)
zom.SetFloat("rotation",0);
else if (enemyAngle >= 67.5f && enemyAngle < 112.5f)
zom.SetFloat("rotation",);
else if (enemyAngle >= 112.5f && enemyAngle < 157.5f)
return 4;
else if (enemyAngle >= 157.5f && enemyAngle < 202.5f)
return 5;
else if (enemyAngle >= 202.5f && enemyAngle < 247.5f)
return 6;
else if (enemyAngle >= 247.5f && enemyAngle < 292.5f)
return 7;
else if (enemyAngle >= 337.5f || enemyAngle < 22.5f)
return 1;
else return 0;
}
It hasn’t been quite modified yet for my uses. The first problem is the rotation numbers only appear as 179 to -179 I assume there is an invisible 180 on both sides of the spectrum.
The animator float I am using is one that will be used to make a spectrum of numbers that are 1 to 4 each one triggering a directional idle animation that is like that of doom’s. I DO NOT WANT A SHADER SOLUTION
The enemy angle code won’t work since like doom the sprites are not independent of rotation there rotation numbers are the same as the player’s. This is because my Doom style I want has to of course be like doom so all of the sprites are bill boards.
Or maybe this code does but in my eyes it just won’t get the numbers right because I don’t think the code will convert negative numbers like -160 to 340.
I have been stumped on this for weeks If anyone can just please help and stay here to help me. The code that this thing came from was from another post I have. It looked promising so I wanted to modify it to my needs but sadly the person that made it thought they tackled the problem and were done but not only do the numbers and the if statements need to be modified but get angle index doesn’t even work on the code.
Please help I have been stuck for weeks on this