Anteworld - Outerra Game > Modding: Importer, Tools & Utilities
cant't get to work sound in my mod
(1/1)
fly77:
I am trying the first time to make a simple vehicle model made in blender (just a chassis, with children 4 wheels and a steering wheel, then package importing fbx into outerra converting these to bones) and I got the model working correctly inside outerra so that I indeed can drive around with it, but the model breaks if I try to add any soundfile. As soon as I try to use a soundfile I get the following error
18:23:10.955 ERROR: vehicle::init_chassis: file:///Outerra/packages/fly77/simple-car/Corolla.js(58): ReferenceError: load_sound is not defined (ot::js::vehicle_physics::load_script(): ).
as I spawn the model the vehicle gets blocked without ever hearing any sound whatsoever.
To add the sound i followed instructions at http://xtrac.outerraworld.com/wiki/vehicle modifying the script accordingly.
I created a "drive.ogg" and file placed it in the model's directory inside the package folder.
Can anybody help me to tell me what I am doing wrong ?
--- Code: ---
//--------------------------------------------------------------------------------------------------
// EDIT VARIABLES BELOW TO ADAPT THIS SCRIPT TO YOUR MODEL. DON'T CHANGE VARIABLE NAMES, JUST VALUES
//--------------------------------------------------------------------------------------------------
var EF = 3000.0;
var BF = 13000.0;
var ST = 0.7
var maxkmh = 150;
var forceloss = EF / (0.2*maxkmh + 1);
var soundfile = "drive.ogg" /
var Wh_rad = 0.45
var CarMass = 1120
var WHEEL_FR = "WHEEL-FR"
var WHEEL_FL = "WHEEL-FL"
var WHEEL_RR = "WHEEL-RR"
var WHEEL_RL = "WHEEL-RL"
var STEERING_WHEEL = "STEER-WHEEL"
var steerAngle /
var swheel_id
function init_chassis()
{
var wheelparam = {
radius: Wh_rad,
width: 0.2,
suspension_max: 0.1,
suspension_min: -0.12,
suspension_stiffness: 30.0,
damping_compression: 0.4,
damping_relaxation: 0.12,
grip: 0.5,
roll_influence: 0.1};
this.add_wheel(WHEEL_FR,wheelparam);
this.add_wheel(WHEEL_FL,wheelparam);
this.add_wheel(WHEEL_RR,wheelparam);
this.add_wheel(WHEEL_RL,wheelparam);
this.geom = this.get_geomob(0)
swheel_id = this.geom.get_joint(STEERING_WHEEL);
return {mass:CarMass, steering:2.0, steering_ecf:60, centering: 9.6, centering_ecf:1};
//return {mass:CarMass, steering:2.0, steering_ecf:60, centering: 2.6, centering_ecf:20};
}
// sounds
this.load_sound("drive.ogg");
this.add_sound_emittter("WHEEL_FR");
//------------------------------------------------------------------------------------------------
function init_vehicle(){
this.set_fps_camera_pos({x:-0.39,y:-0.50,z:1.50});
this.snd = this.sound();
this.snd.set_ref_distance(0, 9.0);
this.started = 0;
}
//-----------------------------------------------------------------
function engine(start){
if(start) {
this.started=1;
this.snd.play(0, 0, false, false);
}
}
//==================================================================
function update_frame(dt, engine, brake, steering)
{
var kmh = this.speed()*3.6;
var redux = engine>=0 ? 0.2 : 0.6;
var esign = engine<0 ? -1 : 1;
engine = EF*Math.abs(engine);
var force = (esign>0) == (kmh>=0)
? engine/(redux*Math.abs(kmh) + 1)
: engine;
force -= forceloss;
force = Math.max(0.0, Math.min(force, engine));
engine = esign*force;
brake *= BF;
steering *= ST;
this.steer(-2, steering); // -2 = front wheels used for steering
steerAngle = steering *= 2.05;
this.geom.rotate_joint_orig(swheel_id, steerAngle, {x:0,y:0,z:1});
this.wheel_force(-1, engine);
this.wheel_brake(-11, brake);
this.animate_wheels();
if(this.started==1 && !this.snd.is_playing(0)) {
this.started=2;
this.snd.play(0, 1, true, false);
}
else if(this.started==2) {
var pitch = Math.abs(kmh)/20.0;
var g = kmh>0 ? Math.floor(pitch) : 0;
var f = pitch - g;
f += 0.5*g;
this.snd.set_pitch(0, 0.5*f + 1.0);
}
}
--- End code ---
cameni:
You need to call the load_sound etc inside the init_chassis methods. The "this" object referring to the vehicle physics interface exists only inside the events (init_chassis, init_vehicle, update_frame ...), but not in the global scope.
fly77:
Thanks a lot ! I now got it working after a day of desperate trials. Though to get the sound looping forever I had to do some other modifications as well - copying from the script of the BMW model provided with the new outerra version. Just one thing now i don't know how to stop the sound when switching off the engine. I'll figure out.
Here is the working script for reference:
--- Code: ---/
var EF = 3000.0;
var BF = 13000.0;
var ST = 0.7
var maxkmh = 150;
var forceloss = EF / (0.2*maxkmh + 1);
var Wh_rad = 0.45
var CarMass = 1120
var WHEEL_FR = "WHEEL-FR"
var WHEEL_FL = "WHEEL-FL"
var WHEEL_RR = "WHEEL-RR"
var WHEEL_RL = "WHEEL-RL"
var STEERING_WHEEL = "STEER-WHEEL"
var steerAngle
var swheel_id
var _snd = -1;
var _snd_src = -1;
var soundfile = "drive.ogg" //<-- sound file
var rpm_src_on = 0;
//=============================================================================================
function init_chassis()
{
var wheelparam = {
radius: Wh_rad,
width: 0.2,
suspension_max: 0.1,
suspension_min: -0.12,
suspension_stiffness: 30.0,
damping_compression: 0.4,
damping_relaxation: 0.12,
grip: 0.5,
roll_influence: 0.1};
this.add_wheel(WHEEL_FR,wheelparam);
this.add_wheel(WHEEL_FL,wheelparam);
this.add_wheel(WHEEL_RR,wheelparam);
this.add_wheel(WHEEL_RL,wheelparam);
this.geom = this.get_geomob(0)
swheel_id = this.geom.get_joint(STEERING_WHEEL);
_snd = this.load_sound(soundfile);
_snd_src = this.add_sound_emitter(WHEEL_FR );
_snd_on = this.load_sound(soundfile);
_src_on = this.add_sound_emitter(WHEEL_FR );
return {mass:CarMass, steering:2.0, steering_ecf:60, centering: 9.6, centering_ecf:1};
//return {mass:CarMass, steering:2.0, steering_ecf:60, centering: 2.6, centering_ecf:20};
}
//------------------------------------------------------------------------------------------------
function init_vehicle(){
this.set_fps_camera_pos({x:-0.39,y:-0.50,z:1.50});
this.snd = this.sound();
this.snd.set_ref_distance(0, 9.0);
this.snd.set_ref_distance(_src_on, 9.0);
this.started = 0;
}
//-----------------------------------------------------------------
function engine(start){
if(start) {
this.snd.play(_snd_src, _snd, false, false);
this.started=1;
}
}
//==================================================================
function update_frame(dt, engine, brake, steering)
{
var kmh = this.speed()*3.6;
var redux = engine>=0 ? 0.2 : 0.6;
var esign = engine<0 ? -1 : 1;
engine = EF*Math.abs(engine);
var force = (esign>0) == (kmh>=0)
? engine/(redux*Math.abs(kmh) + 1)
: engine;
force -= forceloss;
force = Math.max(0.0, Math.min(force, engine));
engine = esign*force;
brake *= BF;
steering *= ST;
this.steer(-2, steering); // -2 = front wheels used for steering
steerAngle = steering *= 2.05;
this.geom.rotate_joint_orig(swheel_id, steerAngle, {x:0,y:0,z:1});
this.wheel_force(-1, engine);
this.wheel_brake(-11, brake);
this.animate_wheels();
if(this.started==1 && !this.snd.is_playing(0)) {
this.started=2;
this.snd.play_loop(_src_on, _snd_on);
}
else if(this.started==2) {
var pitch = Math.abs(kmh)/20.0;
var g = kmh>0 ? Math.floor(pitch) : 0;
var f = pitch - g;
f += 0.5*g;
this.snd.set_pitch(_src_on, 0.5*f + 1.0);
}
}
--- End code ---
Navigation
[0] Message Index
Go to full version