I have a basic character set up in an FPS style game I am building. When the player presses W to move forward, I want the game engine to play a walking sound. However, when I link the W keyboard sensor to the sound actuator, anytime I press W in game there is a spike for Logic on the profiler and the game lags a couple milliseconds. My audio file is an mp3, but it does this with WAVs as well. Thoughts?
From what it seems to me, you have a Keyboard Sensor stringed to a And Controller stringed to a Sound Actuator. When in this setup the game will always lag for this reason: when a keyboard key is held, it sends many pulses per second to the computer to act as input. If you have something like a Motion Actuator, then this isn't a problem, as it just makes it move forward continuously. However, with your Sound Actuator, what it's trying to do instead is to start playing the sound file every time it receives a pulse (which by default is 60 times per second). So in effect every frame the key is held it tries to play the sound, which is more than the game engine can handle, and as such it slows down.
Now, a setup that doesn't have the sound playing 60 times at once is as follows
[WARNING: TECHNICAL JARGON AHEAD!]:
First delete the malfunctioning sound actuator part you set up.
Use a different Keyboard Sensor than the one controlling the movement of your character, but assign it the same key (W). Click the
''' icon on the sensor to darken it, then in the frequency box, enter in a number other than zero (the basis of this number is how many frames is in between pulses, for example if you put in 29, then there will be 29 pulse-lengths between every pulse sent to the computer, making the sensor do 2 per second at 60 frames per second. The larger the number the more time in between pulses.) See this page on Sensor Common Options for a little more of an in-depth look on this function.
Then add your And Controller and a Sound Actuator set to use your sound. If everything goes correctly, you should have some evenly-spaced footstep sounds with no lag.
If this was good, consider upvoting! :)