0
$\begingroup$

This has not bothered me for a while. But when working on the finishing touches of my game I seem to rather have it fixed than to keep it that way.*

My problem is simple. When I walk the 'Walk'sound comes up. But when I run the 'Walk'sound continues with the 'Run'sound. That way it seems like there is more than just one person to control.

The workflow that I used to realize the sounds is easy. I used a part of the ground as collision sensor and gave it a 'Collision' Sensor as well as 2 Different 'Keyboard' Sensors. One triggers the walkcycle sound actuator when pressing the 'W' key while the other needs the 'W'+'Shift' key to play the runcycle sound actuator.

When trying to put the sounds on different logic bricks even connected to the Character it self, it did not seem to make any difference. That is why I came up with this very specific question.

If there is anyone who can relate and or solve this mystery please let me know. Also if I have not provided enough info about my current situation reguarding this small sound issue then let me know as well as I am willing to explain the tiniest details if necessary.

Thanks!,

If some info is not clear; this is the actual Logic Brick for one of the floors I use in my game.

enter image description here

$\endgroup$
  • $\begingroup$ BGE How to change a music loop in the middle of a game? should help $\endgroup$ – David Oct 24 '17 at 13:33
  • $\begingroup$ I see how this would work but keep in mind that the walk and run cycle are triggered by a Collision and Keyboard sensor . So figuring this one out is a puzzle yet to be completed. Still I appreciate your input thanks David ;D $\endgroup$ – Sven Koppers Oct 24 '17 at 14:35
0
$\begingroup$

Analyse

Your setup is not exclusive.

This means you can (and do) activate both actuators at the same time. This happens as both are listening to the same keyboard key W. The only difference is the key modifier Left Shift.

Logical Condition - method

You need to exclude the key of the opposite operation when triggering the first operation.

You can do that with an additional keyboard sensor listening to Left Shift as well, but inverting the output [Invert].

This way the logic will be:

W + not Left Shift -> first actuator W + Left Shift -> second actuator

Due to the exclusive conditions the actuators will run exclusive too.

State - method

A better implementation is to use the build-in state machine. This way the operations are guarantied exclusive. You can even use the same key to toggle between walking and running. Example:

State 1: waiting

State 2: walking

State 3: running

  • waiting: when W -> walking
  • walking: when not W -> waiting
  • waiting: when Shift -> running
  • walking: when not W -> waiting
  • waiting: when not Shift -> walking
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.