Flèches droites peuvent changer d'angle #7

Merged
MaximilienBB merged 8 commits from origin/feature/StraightArrowChangesAngle into main 2025-05-30 23:42:35 +00:00
2 changed files with 18 additions and 11 deletions
Showing only changes of commit 1eef2c2dc0 - Show all commits

View File

@ -14,4 +14,4 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
_upgradeUnitCard: {fileID: 11400000, guid: 4728bef0a18b70945bedf5b1190c491e, type: 2} _upgradeUnitCard: {fileID: 11400000, guid: 4728bef0a18b70945bedf5b1190c491e, type: 2}
_upgradePrefab: {fileID: 1436362432952518814, guid: 8d56b160dedb7f84d830d749372fe8e8, type: 3} _upgradePrefab: {fileID: 1436362432952518814, guid: 8d56b160dedb7f84d830d749372fe8e8, type: 3}
_upgradeCardArt: {fileID: 21300000, guid: bc54d5d5ac69f334daf7b36882bd5199, type: 3} _upgradeCardArt: {fileID: 21300000, guid: bf13763ff43b8114b8bdca864dfdf62f, type: 3}

View File

@ -32,6 +32,7 @@ public class Projectile : MonoBehaviour
private float _initialY; private float _initialY;
private float _destinationX; private float _destinationX;
private float _destinationY; private float _destinationY;
private float _enemyPosY = 0f;
private float _speedTime = 0f; private float _speedTime = 0f;
private float _initialXDistance; private float _initialXDistance;
@ -94,22 +95,28 @@ public class Projectile : MonoBehaviour
private void DetStraigthArrowAngle() private void DetStraigthArrowAngle()
{ {
if(_target != null) _enemyPosY = _target.Position.y;
float angleX = (_destinationX) / _initialXDistance; float angleX = (_destinationX) / _initialXDistance;
float angleY = (_destinationY) / _initialYDistance; float angleY = (_destinationY) / _initialYDistance;
Debug.Log("Angle Y: " + angleY); //Obtenir difference entre la position Y du chateau et de l'enemie.
Debug.Log("Angle X: " + angleX); float diffY = transform.position.y - _enemyPosY;
if(angleY >= 1 || angleY <= -1) //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 //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; float lerpStepS;
if(angleX > 0.24 || angleX < -0.24) lerpStepS = Mathf.Rad2Deg * Mathf.Atan(angleX / angleY); if(angleX > 0.235) lerpStepS = Mathf.Rad2Deg * Mathf.Atan(angleX / angleY);
else if(angleX > 0.09 || angleX < -0.09) lerpStepS = -Mathf.Rad2Deg * Mathf.Atan(angleY / angleX); 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); float angleS = Mathf.Lerp(lerpStepS, 0, 0);
transform.eulerAngles = new Vector3(0, 0, angleS); transform.eulerAngles = new Vector3(0, 0, angleS);