Flèches droites peuvent changer d'angle #7
@ -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<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);
|
||||
|
||||
|
||||
_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
|
||||
{
|
||||
|
MaximilienBB marked this conversation as resolved
Outdated
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user
Peut-être ajouter des commentaires détaillant ce que font les IF, pour faciliter la maintenance plus tard. Que ce soit ce que les IF font, ou bien ce que les conditions signifient