From d454865a24b4b608bbbe70660ace9ae136f4c130 Mon Sep 17 00:00:00 2001 From: MaximilienBlanchardBizien1 Date: Sat, 22 Mar 2025 16:35:44 -0400 Subject: [PATCH] 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. --- Assets/Scripts/Projectile.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Assets/Scripts/Projectile.cs b/Assets/Scripts/Projectile.cs index 1077140..612f3f9 100644 --- a/Assets/Scripts/Projectile.cs +++ b/Assets/Scripts/Projectile.cs @@ -97,13 +97,20 @@ public class Projectile : MonoBehaviour float angleX = (_destinationX) / _initialXDistance; float angleY = (_destinationY) / _initialYDistance; - Debug.Log("Angle X: " + angleX); Debug.Log("Angle Y: " + angleY); + Debug.Log("Angle X: " + angleX); if(angleY >= 1 || angleY <= -1) { - float lerpStepS = Mathf.Rad2Deg * Mathf.Atan(angleX / angleY); - //TODO: Determiner les angles x et y que la fleche doit prendre selon l'angle qu'elle est tiree. + //TODO: L'angle fonctionne mieux, mais il y a toujours des problemes avec les angles pret de X + //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); transform.eulerAngles = new Vector3(0, 0, angleS); }