From ad66f2e22cb6bc64c741f0429ae79b2160f1f292 Mon Sep 17 00:00:00 2001 From: MaximilienBlanchardBizien1 Date: Mon, 3 Mar 2025 14:56:47 -0500 Subject: [PATCH 1/7] Created Dynamic Angle Basis Created the foundations for the angle logic that the straight projectile will use when it fires from an angle. --- Assets/Scripts/Projectile.cs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/Assets/Scripts/Projectile.cs b/Assets/Scripts/Projectile.cs index 537ce3e..1077140 100644 --- a/Assets/Scripts/Projectile.cs +++ b/Assets/Scripts/Projectile.cs @@ -1,3 +1,4 @@ +using System; using System.Collections; using System.Collections.Generic; using UnityEngine; @@ -30,9 +31,11 @@ public class Projectile : MonoBehaviour private float _initialX; private float _initialY; private float _destinationX; + private float _destinationY; private float _speedTime = 0f; private float _initialXDistance; + private float _initialYDistance; private void Start() { @@ -40,23 +43,28 @@ public class Projectile : MonoBehaviour _initialX = transform.position.x; _initialY = transform.position.y; _destinationX = _vectorEnd.x - _initialX - _enemySpeed; + _destinationY = _vectorEnd.y - _initialY; _detectionLinked.gameObject.GetComponent().EntityLinked = _target; _detectionLinked.gameObject.GetComponent().ProjectileDamage = _damage; _initialXDistance = Mathf.Abs(_initialX - _destinationX); + _initialYDistance = Mathf.Abs(_initialY - _destinationY); } private void Update() { if (straightProjectile) { + transform.position = Vector2.Lerp(new Vector2(_initialX, _initialY), new Vector2(_vectorEnd.x, _vectorEnd.y), _time/_duration); + DetStraigthArrowAngle(); + //TODO: Implementer cette methode pour mieux faire fonctionner le projectile lorsque possible. //transform.LookAt(VectorEnd, Vector3.forward); - + _time += Time.deltaTime; if (transform.position.x >= _vectorEnd.x) @@ -83,6 +91,24 @@ public class Projectile : MonoBehaviour } } + private void DetStraigthArrowAngle() + { + + float angleX = (_destinationX) / _initialXDistance; + float angleY = (_destinationY) / _initialYDistance; + + Debug.Log("Angle X: " + angleX); + Debug.Log("Angle Y: " + angleY); + + 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. + float angleS = Mathf.Lerp(lerpStepS, 0, 0); + transform.eulerAngles = new Vector3(0, 0, angleS); + } + } + //Getter and Setter public float EnemySpeed { -- 2.34.1 From d454865a24b4b608bbbe70660ace9ae136f4c130 Mon Sep 17 00:00:00 2001 From: MaximilienBlanchardBizien1 Date: Sat, 22 Mar 2025 16:35:44 -0400 Subject: [PATCH 2/7] 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); } -- 2.34.1 From 1eef2c2dc017d09c156c897c83dbd43c1903393a Mon Sep 17 00:00:00 2001 From: MaximilienBlanchardBizien1 Date: Sun, 4 May 2025 19:50:00 -0400 Subject: [PATCH 3/7] Fixed Angle Conditional Logic - Fixed the conditional the projectile class uses to determine if a projectile should be angled or not; - Fixed an issue where the graphic for the castle upgrade was missing. --- .../Buildings/Upgrade_Castle.asset | 2 +- Assets/Scripts/Projectile.cs | 27 ++++++++++++------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/Assets/Design/UnitUpgrades/Buildings/Upgrade_Castle.asset b/Assets/Design/UnitUpgrades/Buildings/Upgrade_Castle.asset index aa16817..6189ed1 100644 --- a/Assets/Design/UnitUpgrades/Buildings/Upgrade_Castle.asset +++ b/Assets/Design/UnitUpgrades/Buildings/Upgrade_Castle.asset @@ -14,4 +14,4 @@ MonoBehaviour: m_EditorClassIdentifier: _upgradeUnitCard: {fileID: 11400000, guid: 4728bef0a18b70945bedf5b1190c491e, type: 2} _upgradePrefab: {fileID: 1436362432952518814, guid: 8d56b160dedb7f84d830d749372fe8e8, type: 3} - _upgradeCardArt: {fileID: 21300000, guid: bc54d5d5ac69f334daf7b36882bd5199, type: 3} + _upgradeCardArt: {fileID: 21300000, guid: bf13763ff43b8114b8bdca864dfdf62f, type: 3} diff --git a/Assets/Scripts/Projectile.cs b/Assets/Scripts/Projectile.cs index 612f3f9..8c92a19 100644 --- a/Assets/Scripts/Projectile.cs +++ b/Assets/Scripts/Projectile.cs @@ -32,6 +32,7 @@ public class Projectile : MonoBehaviour private float _initialY; private float _destinationX; private float _destinationY; + private float _enemyPosY = 0f; private float _speedTime = 0f; private float _initialXDistance; @@ -94,22 +95,28 @@ public class Projectile : MonoBehaviour private void DetStraigthArrowAngle() { + if(_target != null) _enemyPosY = _target.Position.y; + float angleX = (_destinationX) / _initialXDistance; float angleY = (_destinationY) / _initialYDistance; + + //Obtenir difference entre la position Y du chateau et de l'enemie. + float diffY = transform.position.y - _enemyPosY; + + //Debug.Log("Angle X: " + angleX); - Debug.Log("Angle Y: " + angleY); - Debug.Log("Angle X: " + angleX); - - if(angleY >= 1 || angleY <= -1) + if(diffY >= 0.1 || diffY <= -0.1) { //TODO: L'angle fonctionne mieux, mais il y a toujours des problemes avec les angles pret de X - //ou ils sont beaucoup trop verticaux. + //ou ils sont beaucoup trop verticaux. + //L'angle a l'air de fonctionner lorsqu'il tire en avant (X positif), mais on dirait qu'il y a un probleme + //lorsque X est negatif. 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); + if(angleX > 0.235) lerpStepS = Mathf.Rad2Deg * Mathf.Atan(angleX / angleY); + + else if (angleX >= 0) 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); -- 2.34.1 From 7904619816eb1bbdd399da18bbec474b437bcb2f Mon Sep 17 00:00:00 2001 From: MaximilienBlanchardBizien1 Date: Sun, 18 May 2025 18:27:54 -0400 Subject: [PATCH 4/7] Update Projectile.cs --- Assets/Scripts/Projectile.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Assets/Scripts/Projectile.cs b/Assets/Scripts/Projectile.cs index 8c92a19..41420bd 100644 --- a/Assets/Scripts/Projectile.cs +++ b/Assets/Scripts/Projectile.cs @@ -76,7 +76,7 @@ public class Projectile : MonoBehaviour } float x = _speedTime; - float y = (_angle*-Mathf.Pow(x, 2) + _destinationX * x); + float y = x >= 0 ? (_angle*-Mathf.Pow(x, 2) + _destinationX * x) : - (_angle * -Mathf.Pow(x, 2) + _destinationX * x); transform.position = new Vector2(_initialX + x*_angle, _initialY + y); @@ -102,21 +102,25 @@ public class Projectile : MonoBehaviour //Obtenir difference entre la position Y du chateau et de l'enemie. float diffY = transform.position.y - _enemyPosY; - + //Debug.Log("Angle X: " + angleX); - if(diffY >= 0.1 || diffY <= -0.1) + if (diffY >= 0.1 || diffY <= -0.1) { //TODO: L'angle fonctionne mieux, mais il y a toujours des problemes avec les angles pret de X //ou ils sont beaucoup trop verticaux. //L'angle a l'air de fonctionner lorsqu'il tire en avant (X positif), mais on dirait qu'il y a un probleme //lorsque X est negatif. + //TODO: Recalculer la vitesse pour qu'elle fonctionne lorsque le projectile est tire en arriere. float lerpStepS; - if(angleX > 0.235) lerpStepS = Mathf.Rad2Deg * Mathf.Atan(angleX / angleY); + if (angleX > 0.23) lerpStepS = Mathf.Rad2Deg * Mathf.Atan(angleX / angleY); else if (angleX >= 0) lerpStepS = Mathf.Rad2Deg * Mathf.Atan(angleY / angleX); - else 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); -- 2.34.1 From b98eeb70aa92599d9dc875fb85697f60dc3e97d7 Mon Sep 17 00:00:00 2001 From: MaximilienBlanchardBizien1 Date: Fri, 30 May 2025 16:22:19 -0400 Subject: [PATCH 5/7] Projectile Code Cleanup Cleaned up the "Projectile.cs" file to remove personal comments and attempted solution to fixing the issue of units not being able to shoot arrows backward. --- Assets/Scripts/Projectile.cs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/Assets/Scripts/Projectile.cs b/Assets/Scripts/Projectile.cs index 41420bd..c87fae9 100644 --- a/Assets/Scripts/Projectile.cs +++ b/Assets/Scripts/Projectile.cs @@ -76,7 +76,7 @@ public class Projectile : MonoBehaviour } float x = _speedTime; - float y = x >= 0 ? (_angle*-Mathf.Pow(x, 2) + _destinationX * x) : - (_angle * -Mathf.Pow(x, 2) + _destinationX * x); + float y = (_angle*-Mathf.Pow(x, 2) + _destinationX * x) transform.position = new Vector2(_initialX + x*_angle, _initialY + y); @@ -100,18 +100,12 @@ public class Projectile : MonoBehaviour float angleX = (_destinationX) / _initialXDistance; float angleY = (_destinationY) / _initialYDistance; - //Obtenir difference entre la position Y du chateau et de l'enemie. + //Obtenir la difference entre la position Y du chateau et de l'enemie. float diffY = transform.position.y - _enemyPosY; - //Debug.Log("Angle X: " + angleX); - if (diffY >= 0.1 || diffY <= -0.1) { - //TODO: L'angle fonctionne mieux, mais il y a toujours des problemes avec les angles pret de X - //ou ils sont beaucoup trop verticaux. - //L'angle a l'air de fonctionner lorsqu'il tire en avant (X positif), mais on dirait qu'il y a un probleme - //lorsque X est negatif. - //TODO: Recalculer la vitesse pour qu'elle fonctionne lorsque le projectile est tire en arriere. + float lerpStepS; if (angleX > 0.23) lerpStepS = Mathf.Rad2Deg * Mathf.Atan(angleX / angleY); -- 2.34.1 From 6b2fe4738d09a517bc793bfdc434fcef43a07550 Mon Sep 17 00:00:00 2001 From: MaximilienBB Date: Fri, 30 May 2025 22:31:34 +0000 Subject: [PATCH 6/7] Actualiser Assets/Scripts/Projectile.cs --- Assets/Scripts/Projectile.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/Scripts/Projectile.cs b/Assets/Scripts/Projectile.cs index c87fae9..d03ae9c 100644 --- a/Assets/Scripts/Projectile.cs +++ b/Assets/Scripts/Projectile.cs @@ -76,7 +76,7 @@ public class Projectile : MonoBehaviour } float x = _speedTime; - float y = (_angle*-Mathf.Pow(x, 2) + _destinationX * x) + float y = (_angle*-Mathf.Pow(x, 2) + _destinationX * x); transform.position = new Vector2(_initialX + x*_angle, _initialY + y); -- 2.34.1 From a6a24a87f8329b53a1909c14c0d8f1540ce71dcb Mon Sep 17 00:00:00 2001 From: MaximilienBlanchardBizien1 Date: Fri, 30 May 2025 19:30:56 -0400 Subject: [PATCH 7/7] =?UTF-8?q?Ajout=C3=A9=20commentaires=20"If"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Des commentaires ont été ajoutés aux conditions qui détermines l'angle qui doit être appliqué aux flèches. --- Assets/Scripts/Projectile.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Assets/Scripts/Projectile.cs b/Assets/Scripts/Projectile.cs index d03ae9c..f513ef9 100644 --- a/Assets/Scripts/Projectile.cs +++ b/Assets/Scripts/Projectile.cs @@ -100,17 +100,27 @@ public class Projectile : MonoBehaviour float angleX = (_destinationX) / _initialXDistance; float angleY = (_destinationY) / _initialYDistance; - //Obtenir la difference entre la position Y du chateau et de l'enemie. + //Obtenir la difference entre la position Y du chateau et de l'ennemie. float diffY = transform.position.y - _enemyPosY; + //D'abord,on regarde si l'ennemi et l'unite sont a la meme hauteur. + //Si ce n'est pas le cas, on modifie l'angle de la fleche. Sinon, on ne change rien. if (diffY >= 0.1 || diffY <= -0.1) { float lerpStepS; - if (angleX > 0.23) lerpStepS = Mathf.Rad2Deg * Mathf.Atan(angleX / angleY); + //Ensuite, on regarde la position entre l'ennemi et l'unite. + //Si cette distance est plus petite qu'un certain nombre, on utilise un calcul differents + //pour determine l'angle que la fleche doit prendre. + if (angleX > 0.23) lerpStepS = Mathf.Rad2Deg * Mathf.Atan(angleX / angleY); + + //Si la position est negative, on utilise un calcul different pour determiner l'angle. + //(Il faudra tester si ca marche lorsque le chateau pourrait tirer en arriere). else if (angleX >= 0) lerpStepS = Mathf.Rad2Deg * Mathf.Atan(angleY / angleX); + //Calcul utilise pour tenter de mieux faire fonctionner l'angle de la fleche lorsque l'ennemi est + //proche de l'unite. else { lerpStepS = -Mathf.Rad2Deg * Mathf.Atan(angleY / angleX); -- 2.34.1