Hello,
I would like to have more than one sound, so once press a key, one sound and then another press of the same key, a different sound. I tried something in blender, I don’t know where to go with this.
Thank you.
Hello,
I would like to have more than one sound, so once press a key, one sound and then another press of the same key, a different sound. I tried something in blender, I don’t know where to go with this.
Thank you.
You can use States. In State 1, you have your Keyboard Sensor(you don’t have to use True level triggering) connected to an And Controller and that is connected to two Actuators. The first Actuator is your sound. The second Actuator is a State Actuator. Set the State Actuator to switch to State 2. In State 2 you have another Keyboard Sensor that uses the same Key as the one in State 1. Connect it to an And Controller and then again connect it to your next sound and another State Actuator. If you just want to have the two sounds alternate, set the State Actuator to go back to State 1. If you want more sounds, just continue this process by adding more States and Keyboard->And->Sound/State combinations until you have what you need.
it can be done in python with randint() and a selection of sounds, you get a random number and play the sound associated to it from a dictionary.
from random import randint
#actuators called sound1, sound2, sound3 and sound4, each with a different sound
soundDict = {'0': 'sound1', '1': 'sound2', '2': 'sound3', '3': 'sound4'}
#get a random number
plays = randint(0, 3)
cont.activate(soundDict[str(plays)]) #this must activate the actuator that corresponds to the random number
with logic bricks you could change a property and check for that property to play a sound.
if “sound” == 0 and you press R
, it plays one sound. if “sound” == 1 and you press R
, it plays a different sound, and a different one if it is 2, etc. then you connect the keyboard R
sensor to an actuator that adds 1 to the property, and if the property reaches certain number (like 4), it changes it to 0. the limitation is that the sounds are always played in the same order.
Another way to do it without state changes and sticking with logic bricks(i prefer python myself but that’s just personal preference) is something similar to what it looked like you were doing in your screen shot. You just needed to add Property Actuators to the mix. I used Tap on the Keyboard Sensor to keep it from cycling too fast. You can add more sounds by just adding more Property Sensors and more Sound Actuators. No need to add more Property Add Actuators as you can just reuse the one there already as well as reusing the Keyboard Sensor. Just make sure your last Sound Actuator is also tied to the Property Set Actuator to go back to your first sound.
So many ways to do things in Blender.
sorry just saw your logic brick explanation after i replied