Hi community,
I’m writing a flame-thrower code, but the flames don’t scale/increase velocity… :?
This is the code:
var Range = 6.0;
var Damage = 10;
var force = 3.0;
var MaxFlameEmission = 60;
var MinFlameEmission = 10;
var Flames : ParticleEmitter;
var GetsBurned : Transform;
private var attack : boolean = false;
var maxFlameVelocity : Vector3;
var minFlameVelocity : Vector3;
audio.Play();
audio.loop = true;
function Fire (burn : boolean) {
attack = burn;
if (burn) {
audio.pitch = 2.0;
Flames.maxEmission = MaxFlameEmission;
Flames.minEmission = MaxFlameEmission;
Flames.localVelocity = maxFlameVelocity;
Flames.maxSize *= 2c;
yield new WaitForSeconds(0.4);
burn = false;
Flames.localVelocity = minFlameVelocity;
Flames.maxEmission = MinFlameEmission;
Flames.minEmission = MinFlameEmission;
Flames.maxSize /= 2;
audio.pitch = 1.0;
}
else {
}
}
function Update () {
var direction = transform.forward;
var hit : RaycastHit;
if (attack == true) {
// Did we hit anything?
if (Physics.Raycast (transform.position, direction, hit, Range))
{
// Apply a force to the rigidbody we hit
if (hit.rigidbody)
hit.rigidbody.AddForceAtPosition(force * direction, hit.point);
// Send a damage message to the hit object
hit.collider.SendMessageUpwards("ApplyDamage", Damage/2, SendMessageOptions.DontRequireReceiver);
}
}
}
The damage part is working, but the one that scales/accelerates the particles does nothing at all…
I solved the problem:
var Range = 6.0;
var Damage = 10;
var force = 3.0;
var MaxFlameEmission = 60;
var MinFlameEmission = 10;
var Flames : ParticleEmitter;
var GetsBurned : Transform;
var attack : boolean = false;
var maxFlameVelocity : Vector3;
var minFlameVelocity : Vector3;
var burn : boolean = true;
audio.Play();
audio.loop = true;
function Fire () {
attack = burn;
if (burn == true) {
attack = true;
audio.pitch = 2.0;
Flames.maxEmission = MaxFlameEmission;
Flames.minEmission = MaxFlameEmission;
Flames.localVelocity = maxFlameVelocity;
Flames.maxSize *= 2;
yield new WaitForSeconds(0.4);
Flames.localVelocity = minFlameVelocity;
Flames.maxEmission = MinFlameEmission;
Flames.minEmission = MinFlameEmission;
Flames.maxSize /= 2;
audio.pitch = 1.0;
yield new WaitForSeconds(0.1);
attack = false;
}
else {
Flames.localVelocity = minFlameVelocity;
Flames.maxEmission = MinFlameEmission;
Flames.minEmission = MinFlameEmission;
Flames.maxSize /= 2;
audio.pitch = 1.0;
}
}
function Update () {
var direction = transform.forward;
var hit : RaycastHit;
if (attack == true) {
// Did we hit anything?
if (Physics.Raycast (transform.position, direction, hit, Range))
{
// Apply a force to the rigidbody we hit
if (hit.rigidbody)
hit.rigidbody.AddForceAtPosition(force * direction, hit.point);
// Send a damage message to the hit object
hit.collider.SendMessageUpwards("ApplyDamage", Damage/2, SendMessageOptions.DontRequireReceiver);
// Place the particle system for spawing out of place where we hit the surface!
// And spawn a couple of particles
}
}
}