Skip to content

Instantly share code, notes, and snippets.

@SenpaiRar
Created May 6, 2020 08:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SenpaiRar/316f1443ffe4f3210c2b66706d3cb93d to your computer and use it in GitHub Desktop.
Save SenpaiRar/316f1443ffe4f3210c2b66706d3cb93d to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ParabolicBullet : Bullet
{
Vector2 StartPoint;
Vector2 EndPoint;
Vector2 CurvePoint;
Vector2 Derv;
public GameObject FirstPoint;
public GameObject SecondPoint;
public GameObject ThirdPoint;
public float Speed;
public int Damage;
float p;
float tOff;
private void Start(){
p = 0;
StartPoint = new Vector2(FirstPoint.transform.position.x, FirstPoint.transform.position.z);
EndPoint = new Vector2(SecondPoint.transform.position.x, SecondPoint.transform.position.z);
CurvePoint = new Vector2(ThirdPoint.transform.position.x, ThirdPoint.transform.position.z);
tOff = Time.time;
}
private void Update(){
StartPoint = new Vector2(FirstPoint.transform.position.x, FirstPoint.transform.position.z);
EndPoint = new Vector2(SecondPoint.transform.position.x, SecondPoint.transform.position.z);
CurvePoint = new Vector2(ThirdPoint.transform.position.x, ThirdPoint.transform.position.z);
transform.position = new Vector3(CalculatePosition(p).x, 0, CalculatePosition(p).y);
p = Mathf.PingPong((Time.time-tOff)*Speed, 1);
if(p>0.9f){
Destroy(gameObject);
}
}
void OnTriggerEnter(Collider col){
if(col.tag == "Enemy" || col.tag=="Enemy_Bullet"){
col.GetComponent<Entity>().TakeDamage(Damage);
}
}
public override int GetDamage(){
return Damage;
}
Vector2 CalculatePosition(float t){
Vector2 B;
B = (Mathf.Pow(1-t,2)*StartPoint) + ((2*(1-t))*t*CurvePoint) + (Mathf.Pow(t,2)*EndPoint);
return(B);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment