Game Development Community

Flying Vehicle Engine Sound (bug?) - RESOLVED

by Donald Teal · in Torque 3D Professional · 03/26/2011 (6:41 am) · 14 replies

Torque3d 1.1B3
Win7

FlyingVehicle does not play engine sound unless colliding with a waterblock


I think I have some hair left, but after the last couple of sessions I pulled out more than I have left.

I have been trying to implement an engine sound for my flying vehicle. A look at the flying vehicle data shows an entry for engineSound=" ";

I have a mono .ogg file engine.ogg so I change that line to read engineSound="DirigibleEngine";

and i create the datablock

datablock SFXProfile(DirigibleEngine)
{
filename = "art/sound/engine";
description = Audio2d;
};


So I load up T3D and go to where my flying vehicle is and no sound. look in console... no errors
so I think maybe sound only plays when the vehicle moves so I mount the vehicle and fly around .. no sound. I fly over a small water block and fly into it. guess what while I am in the waterblock the engine sound plays. Leave the waterblock.. no more engine sound.


This cant be right, look in the code, yeah engineSound is set to be the base engine sound. nothing about collision with waterblocks.

I have tried different sound files, I have tried engineSound= DirigibleEngine; and engineSound="DirigibleEngine";

not sure if this is a bug or if I am doing something wrong but the sound playing in a water block is really confusing me



#1
03/26/2011 (8:44 am)
So, flying vehicles are boats? lol
#2
03/26/2011 (10:22 am)
Which one is broken,jetSound or engineSound?
Also try to update your code:

void FlyingVehicle::updateEngineSound(F32 level)
{
   if ( mEngineSound ) 
   {
      if ( !mEngineSound->isPlaying() ) mEngineSound->play();//new line

      mEngineSound->setTransform( getTransform() );
      mEngineSound->setVelocity( getVelocity() );
      mEngineSound->setVolume( level );
   }
}
#3
03/26/2011 (2:02 pm)
@Ivan.

That didnt help.

I had a mistake in my datablock my audio description was set to Audio2D and your change worked and I could hear the engine sound all over the map. but when I corrected my datablock to use AudioDefault3D it wouldnt work. Mich has confirmed there seems to be a bug in the SFX code.

#4
04/06/2011 (2:53 pm)
Logged as THREED-1556.
#5
04/26/2011 (10:16 pm)
Has there been any update to this? its kinda annoying not having engine sounds on flying vehicles

and this issue is present in 1.1 Preview as well
#6
04/27/2011 (6:16 am)
Just as an update.. I was comparing the code between the WheeledVehicle.ccp and the flyingVehicle.ccp and I found this in the FlyingVehicle.ccp
void FlyingVehicle::updateEngineSound(F32 level)
{
   if ( mEngineSound ) 
   {
	if ( !mEngineSound->isPlaying() ) mEngineSound->play();
      
		mEngineSound->setTransform( getTransform() );
		mEngineSound->setVelocity( getVelocity() );
		 mEngineSound->setVolume( level );

and in the wheeledVehicle.ccp

mEngineSound->setPitch( pitch );
}

seeing the difference between those two routines I changed the Flyingvehicle to
void FlyingVehicle::updateEngineSound(F32 level)
{
   if ( mEngineSound ) 
   {
	if ( !mEngineSound->isPlaying() ) mEngineSound->play();
      
		mEngineSound->setTransform( getTransform() );
		mEngineSound->setVelocity( getVelocity() );
		 //mEngineSound->setVolume( level );

   // Adjust pitch
   F32 pitch = ((level) * 1.3f);
   if (pitch < 0.4f)  
      pitch = 0.4f;

   mEngineSound->setPitch( pitch );
   }
}

Now when i did that. the engine sound works but when I mount the flying vehicle and move. the sound does not move with the vehicle.
#7
04/27/2011 (6:44 am)
I was not happy with the Engine sounds always on when
you set the value for sound so I made a simple fix:

This connects to any vehicle based off of vehicle.cpp
The sounds will NOT play until a player mounts the vehicle...

Requires Engine Modifications:

vehicle.h
.....
   bool inLiquid;
   SFXSource* mWakeSound;

   //Mythic Added (near line:198)	
   bool mEngineOn;

   Point3F mCameraOffset; ///< 3rd person camera
......
   bool onAdd();
   void onRemove();

   //Mythic Added  (near line:276)
   void setEngineOn( bool valueB ) { mEngineOn = valueB; };
   bool isEngineOn() { return mEngineOn; };

   /// Interpolates between move ticks @see processTick
......

vehicle.cpp
.......
   mThrottle = 0;
   mJetting = false;

   //Mythic Added (near line:606)
   mEngineOn = false;

   mCameraOffset.set(0,0,0);
......

   stream->writeFlag(mJetting);
   
   //Mythic Added (near line:1562)
   stream->writeFlag(mEngineOn);

   // The rest of the data is part of the control object packet update.
......
   mJetting = stream->readFlag();

   //Mythic Added (near line:1595)
   mEngineOn = stream->readFlag();

   if (stream->readFlag())
      return;
.....
   //Added to end of File
DefineEngineMethod( Vehicle, setEngineOn, void, (bool state), ( false ),
   "Turns Engine Sounds on/off.n" )
{
   object->setEngineOn( state );
}

Now we connect this to the current base 3 vehicle types

Flyingvehicle.cpp (This one was simple)
void FlyingVehicle::advanceTime(F32 dt)
{
   Parent::advanceTime(dt);

	if( isEngineOn() )
	{
		updateEngineSound(1);
		updateJet(dt);
	}
}

WheeledVehicle.cpp (fairly simple)
// Update the sounds based on wheel slip and torque output
	if( isEngineOn() )
	{
		updateSquealSound(slipTotal / mDataBlock->wheelCount);
		updateEngineSound(sIdleEngineVolume + (1 - sIdleEngineVolume) * (1 - (torqueTotal / mDataBlock->wheelCount)));
		updateJetSound();
	}

   updateWheelThreads();

Then to connect it finally in script....
scripts/server/player.cs

in the functions onMount/unMount we disable/enable the sounds
this is a very simple implementation, (No Keys *grin*)

function Armor::onMount(...)
{
....
      %obj.unmountImage($WeaponSlot);

      %obj.setControlObject(%vehicle);
      //%obj.client.setObjectActiveImage(%vehicle, 2);
      %vehicle.setEngineOn(true);
   }
   else
   {
      if (%vehicle.getDataBlock().mountPose[%node] !$= "")
.....
}

function Armor::onUnmount(%this, %obj, %vehicle, %node)
{
   %obj.setActionThread("run", true, true);
   if (%node == 0)
   {
      %obj.mountImage(%obj.lastWeapon, $WeaponSlot);
      %obj.setControlObject("");
      %vehicle.setEngineOn(false);
   }
}

That might help some..
:)
#8
04/27/2011 (11:49 am)
@john,

did you try this with a simple flying vehicle? cause I am still having the same issue. except the sound plays when I mount but stays in the same position
#9
04/27/2011 (4:34 pm)
Sorry, not yet, Im still working on Converting some mods
that I use. Those have been enuff of a headache :(
Once I get the basics where Im happy, I'll be digging
into the vehicles next... I do want tanks maybe planes *chuckle*

Will post any results when I get back to vehicles tho.
#10
04/27/2011 (6:59 pm)
Hey there, I'm looking into your issue : )

Can you get me the datablock/art/etc for the FlyingVehicle? (Or a link to the reference where you have yours from?)

None of the examples I have access to (FPS Example, Full and Empty templates, Physics Demo, and a couple others) have a flying vehicle implemented in them. If you can handoff the FlyingVehicle to me, I'd be glad to test and look into fixing this issue.

.zip up and e-mail me any files necessary to the e-mail in my GarageGames profile, please : )

And Thank You!
#11
04/28/2011 (4:31 pm)
@Mythic: I will log a feature request for the code segment you've provided. I understand that most people may/may not want their engine sounds always on.

@Donald: I took a look at it, was able to fix it with the following code change. Similar to yours, now that I look at it : P

in C:\Projects\Torque3D\trunk\Engine\source\T3D\vehicles\flyingVehicle.cpp

Replace the FlyingVehicle::updateEngineSound() function with the following:

void FlyingVehicle::updateEngineSound(F32 level)
{
   if ( !mEngineSound )
      return;

   if ( !mEngineSound->isPlaying() )
      mEngineSound->play();

   mEngineSound->setTransform( getTransform() );
   mEngineSound->setVelocity( getVelocity() );

   mEngineSound->setPitch( level );
}

With this change I heard the FlyingVehicle's engine sound while idle, I could hear it move around when I moved the object in the World Editor, and was able to get in the vehicle and move around with the sound following me... Make sure that when you mount the player, you're doing both of the following.

%vehicle.mountObject(%player, %node) //Calling mountobject on the vehicle;
%player.mVehicle = %vehicle; //And setting the player's mVehicle to the vehicle.
#12
04/28/2011 (7:06 pm)
Ray,

I did these changes in 1.1B3 and no luck. but they work fine in 1.1preview looking at the difference between flyingVehicles.cpp in B3 and flyingVehicles.cpp in preview doesnt look too different. So i can only assume there is something more in the SFX section of the code that was changed between 1.1B3 and 1.1preview. Unfortunately for me, preview is unusable for me because of only have 1 available bitmask. :(
#13
05/06/2011 (5:48 pm)
Fixed in 1.1 Final.
#14
09/19/2012 (2:44 am)
"so I think maybe sound only plays when the vehicle moves so I mount the vehicle and fly around .. no sound. I fly over a small water block and fly into it. guess what while I am in the waterblock the engine sound plays. Leave the waterblock.. no more engine sound."

i am having same problem(may be worse) with helicopter made from this resource:
http://www.garagegames.com/community/resources/view/19569


only difference is that it does not always play engine sound in water.



i have tried all updateEngineSound() function of other vehicle.but no luck.

"Fixed in 1.1 Final."
may be it was fixed for flying vehicle.
but not for others custom vehicle.

so SCOTT,what actually u did to fix it?

07/09/12
[solved]