Created
August 16, 2013 04:58
-
-
Save SteveSwink/6247438 to your computer and use it in GitHub Desktop.
Trying to get TF2 style medic gun particles to flow down a bezier...goes a bit funky
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class LaserLine : MonoBehaviour { | |
float timer; | |
public float duration = 5.0f; | |
public Transform P1; | |
public Transform P2; | |
public Transform P3; | |
public GameObject particle; | |
ParticleSystem particleSystem; | |
int count; | |
void Start () { | |
particleSystem = particle.GetComponent<ParticleSystem>(); | |
} | |
void ResetTimer(){ | |
timer = Time.timeSinceLevelLoad + 1.0f; | |
} | |
public Vector3 GetBezierPoint(Vector3 P1, Vector3 P2, Vector3 P3, float t){ | |
return (P1*(1-t)*(1-t)+ 2*P2*(t)*(1-t) + P3*t*t); | |
} | |
void LateUpdate () { | |
ParticleSystem.Particle[] p = new ParticleSystem.Particle[particleSystem.particleCount+1]; | |
int l = particleSystem.GetParticles(p); | |
int i = 0; | |
while (i < l) { | |
p[i].velocity = GetBezierPoint(P3.position, P2.position, P1.position, Mathf.Lerp (0,1, p[i].lifetime / p[i].startLifetime)); //new Vector3(0, p[i].lifetime / p[i].startLifetime * 10F, 0); | |
i++; | |
} | |
particleSystem.SetParticles(p, l); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment