Created Dynamic Angle Basis

Created the foundations for the angle logic that the straight projectile will use when it fires from an angle.
This commit is contained in:
MaximilienBlanchardBizien1 2025-03-03 14:56:47 -05:00
parent 05a9fa2112
commit ad66f2e22c

View File

@ -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,20 +43,25 @@ public class Projectile : MonoBehaviour
_initialX = transform.position.x;
_initialY = transform.position.y;
_destinationX = _vectorEnd.x - _initialX - _enemySpeed;
_destinationY = _vectorEnd.y - _initialY;
_detectionLinked.gameObject.GetComponent<Detection>().EntityLinked = _target;
_detectionLinked.gameObject.GetComponent<Detection>().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);
@ -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
{