Speedometer

De DigiWiki.

It will Give your speed in KPH, rounded to the nearest KPH.

It works by subtracting the x, y, z values of the current pos, and the pos from 0.5 seconds ago.

It then works out the horizontal distance traveled, square root of (square root of( (x1*x2) + (y1*y2) ) * square root of ( z1 * z2 )))

// Speedometer v1.0 by Jimmy Roo
 
vector current;
vector new;
float xvalue;
float yvalue;
float zvalue;
 
default
{
    state_entry()
    {
        vector current = llGetPos();
        llSetTimerEvent(0.5);
    }
 
    timer()
    {
        new = llGetPos();
 
        if ( new.x < current.x)  {xvalue = current.x - new.x;}
        if ( new.x > current.x)  {xvalue = new.x - current.x;}
        if ( new.x == current.x) {xvalue = new.x - current.x;}
        if ( new.y < current.y)  {yvalue = current.y - new.y;}
        if ( new.y > current.y)  {yvalue = new.y - current.y;}
        if ( new.y == current.y) {yvalue = new.y - current.y;}
        if ( new.z < current.z)  {zvalue = current.z - new.z;}
        if ( new.z > current.z)  {zvalue = new.z - current.z;}
        if ( new.z == current.z) {zvalue = new.z - current.z;}
 
        float beforevalue = llSqrt((yvalue * yvalue) + (xvalue * xvalue));
        float aftervalue =  llSqrt((beforevalue * beforevalue) + (zvalue * zvalue));
 
        llSetText((string)llRound((7.2 * aftervalue)) + " KPH", <1,1,1>, 1.0);
        current = new;
    }
}
Outils personnels
  • Cette page a été consultée 569 fois.
donate
Google Ads