From ad66f2e22cb6bc64c741f0429ae79b2160f1f292 Mon Sep 17 00:00:00 2001 From: MaximilienBlanchardBizien1 Date: Mon, 3 Mar 2025 14:56:47 -0500 Subject: [PATCH] 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 {