Updated Straight Projectile Workings

Updated the function that changes the angle of the straigth projectile to work better the closer the enemy is to the shooter.

There is some more fixes to be done, as those close angles are too vertical.
This commit is contained in:
MaximilienBlanchardBizien1 2025-03-22 16:35:44 -04:00
parent ad66f2e22c
commit d454865a24

View File

@ -97,13 +97,20 @@ public class Projectile : MonoBehaviour
float angleX = (_destinationX) / _initialXDistance; float angleX = (_destinationX) / _initialXDistance;
float angleY = (_destinationY) / _initialYDistance; float angleY = (_destinationY) / _initialYDistance;
Debug.Log("Angle X: " + angleX);
Debug.Log("Angle Y: " + angleY); Debug.Log("Angle Y: " + angleY);
Debug.Log("Angle X: " + angleX);
if(angleY >= 1 || angleY <= -1) if(angleY >= 1 || angleY <= -1)
{ {
float lerpStepS = Mathf.Rad2Deg * Mathf.Atan(angleX / angleY); //TODO: L'angle fonctionne mieux, mais il y a toujours des problemes avec les angles pret de X
//TODO: Determiner les angles x et y que la fleche doit prendre selon l'angle qu'elle est tiree. //ou ils sont beaucoup trop verticaux.
float lerpStepS;
if(angleX > 0.24 || angleX < -0.24) lerpStepS = Mathf.Rad2Deg * Mathf.Atan(angleX / angleY);
else if(angleX > 0.09 || angleX < -0.09) lerpStepS = -Mathf.Rad2Deg * Mathf.Atan(angleY / angleX);
else lerpStepS = Mathf.Rad2Deg * Mathf.Atan(angleY / angleX);
float angleS = Mathf.Lerp(lerpStepS, 0, 0); float angleS = Mathf.Lerp(lerpStepS, 0, 0);
transform.eulerAngles = new Vector3(0, 0, angleS); transform.eulerAngles = new Vector3(0, 0, angleS);
} }