Created
July 29, 2011 04:40
-
-
Save keijiro/1113142 to your computer and use it in GitHub Desktop.
Particle attractor (Unity)
This file contains 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
var target : Vector3; | |
var power = 5.0; | |
function LateUpdate () { | |
var particles = particleEmitter.particles; | |
for (var i = 0; i < particles.Length; i++) { | |
var rp = target - particles[i].position; | |
if (rp.magnitude < 0.5) { | |
// 近づき過ぎたパーティクルを消す。 | |
particles[i].energy = 0.0; | |
} else { | |
// 加速処理。 | |
particles[i].velocity += rp * (power / rp.sqrMagnitude * Time.deltaTime); | |
} | |
} | |
particleEmitter.particles = particles; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment