11.07.2015 Views

Linden Scripting Language Guide - Engineering Center

Linden Scripting Language Guide - Engineering Center

Linden Scripting Language Guide - Engineering Center

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 11. VehiclesSetting the motor speed is not enough to enable all interesting vehicles. For example, some will want a car thatimmediately gets up to the speed they want, while others will want a boat that slowly climbs up to its maximumvelocity. To control this effect you can use the VEHICLE_LINEAR_MOTOR_TIMESCALE parameter.Basically the "timescale" of a motor is the time constant for the vehicle to exponentially accelerate toward its fullspeed.What would happen if you were to accidentally set the vehicle’s linear velocity to maximum possible speed andthen let go? It would run away and never stop, right? Not necessarily: an automatic "motor decay" has been builtin such that all motors will gradually decrease their effectiveness after being set.Each time the linear motor’s vector is set its "grip" immediately starts to decay exponentially with a timescaledetermined by the VEHICLE_LINEAR_MOTOR_DECAY_TIMESCALE, such that after enough time themotor ceases to have any effect. This decay timescale serves two purposes. First, since it cannot be set longerthan 120 seconds, and is always enabled it gaurantees that a vehicle will not push itself about forever in theabsence of active control (from keyboard commands or some logic loop in the script). Second, it can be used topush some vehicles around using a simple impulse model. That is, rather than setting the motor "on" or "off"depending on whether a particular key is pressed "down" or "up" the decay timescale can be set short and themotor can be set "on" whenever the key transitions from "up" to "down" and allowed to automatically decay.Since the motor’s effectiveness is reset whenever the motor’s vector is set, then setting it to a vector of lengthzero is different from allowing it to decay completely. The first case will cause the vehicle to try to reach zerovelocity, while the second will leave the motor impotent.The two motor timescales have very similar names, but have different effects, so try not to get them confused.VEHICLE_LINEAR_MOTOR_TIMESCALE is the time for motor to "win", andVEHICLE_LINEAR_MOTOR_DECAY_TIMESCALE is the time for the motor’s "effectiveness" to decaytoward zero. If you set one when you think you are changing the other you will have frustrating results. Also, ifthe motor’s decay timescale is shorter than the regular timescale, then the effective magnitude of the motorvector will be diminished.11.7. Steering the VehicleMuch like the linear motor, there is also an angular motor that is always on, and whose direction and magnitudecan be set. For example, to make a vehicle turn at 5 degrees/sec around it’s local z-axis (its up-axis) you mightadd the following lines to its script:vector angular_velocity = ;llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, angular_velocity);The magnitude of the angular motor is capped to be no more than two rotations per second (4*PI radians/sec).Also like the linear motor it has an efficiency parameter, VEHICLE_ANGULAR_MOTOR_TIMESCALE, and amotor decay parameter, VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, which is set to the30

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!