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:
parent
05a9fa2112
commit
ad66f2e22c
@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@ -30,9 +31,11 @@ public class Projectile : MonoBehaviour
|
|||||||
private float _initialX;
|
private float _initialX;
|
||||||
private float _initialY;
|
private float _initialY;
|
||||||
private float _destinationX;
|
private float _destinationX;
|
||||||
|
private float _destinationY;
|
||||||
private float _speedTime = 0f;
|
private float _speedTime = 0f;
|
||||||
|
|
||||||
private float _initialXDistance;
|
private float _initialXDistance;
|
||||||
|
private float _initialYDistance;
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
@ -40,23 +43,28 @@ public class Projectile : MonoBehaviour
|
|||||||
_initialX = transform.position.x;
|
_initialX = transform.position.x;
|
||||||
_initialY = transform.position.y;
|
_initialY = transform.position.y;
|
||||||
_destinationX = _vectorEnd.x - _initialX - _enemySpeed;
|
_destinationX = _vectorEnd.x - _initialX - _enemySpeed;
|
||||||
|
_destinationY = _vectorEnd.y - _initialY;
|
||||||
|
|
||||||
_detectionLinked.gameObject.GetComponent<Detection>().EntityLinked = _target;
|
_detectionLinked.gameObject.GetComponent<Detection>().EntityLinked = _target;
|
||||||
_detectionLinked.gameObject.GetComponent<Detection>().ProjectileDamage = _damage;
|
_detectionLinked.gameObject.GetComponent<Detection>().ProjectileDamage = _damage;
|
||||||
|
|
||||||
_initialXDistance = Mathf.Abs(_initialX - _destinationX);
|
_initialXDistance = Mathf.Abs(_initialX - _destinationX);
|
||||||
|
_initialYDistance = Mathf.Abs(_initialY - _destinationY);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
if (straightProjectile)
|
if (straightProjectile)
|
||||||
{
|
{
|
||||||
|
|
||||||
transform.position = Vector2.Lerp(new Vector2(_initialX, _initialY),
|
transform.position = Vector2.Lerp(new Vector2(_initialX, _initialY),
|
||||||
new Vector2(_vectorEnd.x, _vectorEnd.y), _time/_duration);
|
new Vector2(_vectorEnd.x, _vectorEnd.y), _time/_duration);
|
||||||
|
|
||||||
|
DetStraigthArrowAngle();
|
||||||
|
|
||||||
//TODO: Implementer cette methode pour mieux faire fonctionner le projectile lorsque possible.
|
//TODO: Implementer cette methode pour mieux faire fonctionner le projectile lorsque possible.
|
||||||
//transform.LookAt(VectorEnd, Vector3.forward);
|
//transform.LookAt(VectorEnd, Vector3.forward);
|
||||||
|
|
||||||
_time += Time.deltaTime;
|
_time += Time.deltaTime;
|
||||||
|
|
||||||
if (transform.position.x >= _vectorEnd.x)
|
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
|
//Getter and Setter
|
||||||
public float EnemySpeed
|
public float EnemySpeed
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user