ビークル用テンプレート

// ==================================================================================================================================================
//                                                                                                                      VEHICLE PHYSICAL CONTROL UNIT
// ==================================================================================================================================================
vector VPos; rotation VRot; float VV; float VA; float VEA; integer VType; float VBuoyancy; rotation VAxisRot; integer VFlags; float VLMDelay;
vector VLMOffset; vector VLMFriction; float VLMResponse; float VLMDecay; vector ObjectiveVel; vector ObjectiveRad; float VAMResponse; float VAMDelay;
float VAMDecay; float VAMDef; float VLMDef; float VBankMag; float VBankStatic; float VVAResponse; float VVAPower; integer ON = -1; integer OFF = 0;
uuUpdateVehicleParams(integer reset){//------------------------------------------------------------------------- uuUpdateVehicleParams(integer reset)
    if (reset){
              VFlags =(    VEHICLE_FLAG_NO_DEFLECTION_UP & OFF
                    )|(     VEHICLE_FLAG_LIMIT_ROLL_ONLY & ON
                    )|(    VEHICLE_FLAG_HOVER_WATER_ONLY & OFF
                    )|(  VEHICLE_FLAG_HOVER_TERRAIN_ONLY & OFF
                    )|( VEHICLE_FLAG_HOVER_GLOBAL_HEIGHT & OFF
                    )|(       VEHICLE_FLAG_HOVER_UP_ONLY & OFF
                    )|(      VEHICLE_FLAG_LIMIT_MOTOR_UP & OFF
                    )|(     VEHICLE_FLAG_MOUSELOOK_STEER & OFF
                    )|(      VEHICLE_FLAG_MOUSELOOK_BANK & OFF
                    )|(    VEHICLE_FLAG_CAMERA_DECOUPLED & OFF
                    );
               VType = VEHICLE_TYPE_CAR;
           VBuoyancy = 0.0;
            VAxisRot = llEuler2Rot(<0.0, 0.0, PI/2>);
           VLMOffset = ZERO_VECTOR;
              VLMDef = 0.95;
         VLMFriction = <1000.0, 0.0, 1000.0>;
         VLMResponse = 2.0;
            VLMDecay = 120.0;
              VAMDef = 1.0;
         VAMResponse = 2.0;
            VAMDecay = 1.5;
            VAMDelay = 2.0;
            VLMDelay = 3.0;
            VBankMag = 1.0;
         VBankStatic = 0.0;
         VVAResponse = 1.0;
            VVAPower = 0.01;
        ObjectiveVel = ZERO_VECTOR;
        ObjectiveRad = ZERO_VECTOR;
    }
    llSetVehicleFloatParam(VEHICLE_BUOYANCY, VBuoyancy); llSetVehicleRotationParam(VEHICLE_REFERENCE_FRAME, VAxisRot); llSetVehicleFlags(VFlags);
    llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_OFFSET, VLMOffset); llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_EFFICIENCY, VVAPower);
    llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, ObjectiveVel); llSetVehicleVectorParam(VEHICLE_LINEAR_FRICTION_TIMESCALE, VLMFriction);
    llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_TIMESCALE, VLMResponse); llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_TIMESCALE, VAMDelay);
    llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, ObjectiveRad); llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_DECAY_TIMESCALE, VLMDecay);
    llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, VAMDecay); llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_TIMESCALE, VAMResponse);
    llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_TIMESCALE, VLMDelay); llSetVehicleFloatParam(VEHICLE_BANKING_EFFICIENCY, VBankMag);
    llSetVehicleFloatParam(VEHICLE_BANKING_MIX, VBankStatic); llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_TIMESCALE, VVAResponse);
    llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_EFFICIENCY, VAMDef); llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_EFFICIENCY, VLMDef);
}
uuVehicleAvailable(integer on){//------------------------------------------------------------------------------------- uuVehicleAvailable(integer on)
    uuUpdateVehicleParams(on); llSetVehicleType(VType * on); llSetStatus(STATUS_PHYSICS, on);
}
uuCheckVehicleCondition(){//----------------------------------------------------------------------------------------------- uuCheckVehicleCondition()
    VPos = llGetPos(); VRot = llGetRot(); vector vel_global = llGetVel(); vector ac_local = llGetAccel() / VRot; vector fwd = llRot2Fwd(VRot);
    vector gnd = <fwd.x, fwd.y, 0.0>; vector elv_angle_rad = llRot2Euler(llRotBetween(gnd, fwd) / VRot); VV = llVecMag(vel_global);
    // VA = ac_local.x;
    VA = ac_local.y;
    // VA = ac_local.z;
    VEA = elv_angle_rad.x * -RAD_TO_DEG;
    // VEA = elv_angle_rad.y * RAD_TO_DEG;
    // VEA = elv_angle_rad.z * RAD_TO_DEG;
}
// ==================================================================================================================================================

uuUpdateVehicleParams(integer reset)

ビークル関連のパラメータをアップデートするユーザ関数。reset = TRUE 時は初期設定を読み込む。すなわち、if(reset){} 内が初期パラメータとなる。control{} イベントや timer{} イベント内で、関連するグローバル変数の値を変更し、末尾でこの関数を走らせる使い方を想定。

uuVehicleAvailable(integer on)

ビークル(物理)のオン / オフの切り替え用ユーザ関数。

uuCheckVehicleCondition()

ビークルの現在の速度、加速度、仰角の取得用ユーザ関数。control{} イベントや timer{} イベントの先頭でこの関数を走らせる使い方を想定。以下のグローバル変数に値を代入する。

  • vector VPos … ビークルの位置(リージョン座標)
  • rotation VRot … ビークルの向き(回転角)
  • float VV … ビークルの速度(単位:m/s | Vehicle Velocity の略)
  • float VA … ビークルの加速度(単位:m/s^2 | Vehicle Acceleration の略)
  • float VEA … ビークルの仰角(単位:° | Vehicle Elevation Angle の略)

注)VA, VEA については、どの軸を使用するかを設定しておく必要がある。