relative velocity and more

Hi!
First of all I have to say that it is a dream come true working with the wonderful piece of software that is UNITY.

I am having some trouble figuring a lot of things out though.
I guess i have two phraseable questions right now

1: how do i figure out if my vehicle is moving forward “in its own coordinate space” the rigidbody,velocity vector gives the velocity in world space.

2: attached to the same gameobject i have a particle system that i want
to control depending on the speed of the gameobject.
how do i find the particle system so that i can reference it in my script?
what i have done is to expose it as a variable and set it in the inspector, this works, but what is the recommended way to get a reference to the particlesystem thru scripting?

TIA

1: transform.InverseTransformDirection is your friend.

2: GetComponent(ParticleEmitter) , GetComponent(ParticleAnimator), or GetComponent(ParticleRenderer) depending on which part of the particle system you need to manipulate. (*)

If you are accessing the particle system often, it’s probably a good idea to call GetComponent inside Start() and store the result in a private variable.


*) The GetComponent syntax shown is the JavaScript syntax. In C# it’s GetComponent( typeof(ParticleEmitter) )

for 1, a better solution would be to take the dot product of the velocity vector and your object’s forward vector.

Vector3.Dot(myObject.rigidbody.velocity,myObject.transform.forward);

if the value is greater than 0, its moving forward in some sense.

EDIT to clarify:
the dot product of a non normalized vector with a normalized vector gives the projection of that vector onto that direction. The value is the magnitude of the velocity in the direction of the objects local forward vector.