Assistance need with particle effects script

Can someone help me fix the syntax in my particle script. I am trying to get it to emit particles from my vehicle when it’s moving, then stop when it’s not moving. I’m pretty sure I’m close!

Thanks in advance!

function Update () {
    if (Vector3.forward > 1){
    	particleEmitter.emit = true;
        	particleEmitter.emit = false;

Movement is something that happens over time, and afaik, there is no inherent “velocity” property you can look at. So, you’re going to have to track position movement yourself. That’s not bad though:

//let's create a var to hold the position from the last frame
private var last_position : Vector3 = null;

//let's see if we moved since last time
var movement = transform.position - last_position;

//let's store our current position as the last position so we can look again later
last_position = transform.position;

if(movement.magnitude) { // we were moving, so do stuff

I’m assuming you are using a rigidbody on your game object? Try this (untested)

var particleVelocityTrigger : Vector3 = Vector3(0,0,0);


 if (rigidbody.velocity == particleVelocityTrigger){

   particleEmitter.emit = false;


   particleEmitter.emit = true;


Note you may need to set a threshold or similar, or even check the against the magnitude of your velocity vector (Vector3.magnitude obviously change the trigger from a Vector3 to a float)

Watch out as well as if this is particles kicked up by the tires you may want to do a grounded check as well :wink:

Vector3.forward is actually a constant vector…
Basically it’s equal to (0,0,1)
so your “if statement” doesn’t make any sense…
it’s like if you were doing :
if (1>1) or something similar :wink:
anyway I guess what you want is : this.transform.forward
this will give you the forward vector in world space
search Transform.forward in the doc (the scripting doc is your best friend…)

also you should use MonoDevelop (free) for scripting / programming
then intellisense or auto completion would be your 2nd best friend !! :wink:
you can also directly compile from MonoDevelop… pretty awesome actually !