Author Topic: Randomized Projectile sounds  (Read 1981 times)

How do i make a projectile randomize sounds while its flying through the air?

You could make a method for the bullet object that plays a random sound then call it every so often.

So, say for a projectile with a datablock name of MyProjectile:

Code: [Select]
function MyProjectile::playSoundTick(%this, %object) {
    %position = %object.getTransform();
    switch(getRandom(0, 2)) {
    case 0:
        %profile = Sound1Profile;
    case 1:
        %profile = Sound2Profile:
    case 2:
        %profile = Sound3Profile;
    }
    serverPlay3D(%profile, %position);
    %this.schedule(1000, playSoundTick, %object);
}

package MyProjectileSound {
    function Projectile::onAdd(%this) {
        if(%this.getDatablock() == MyProjectile)
            MyProjectile.playSoundTick(%this);
        parent::onAdd(%this);
    }
};
activatePackage(MyProjectileSound);

Do you think:
Code: [Select]
serverPlay3D(MySound @ getRandom(1,5),%obj.getPosition());Would work instead?

Do you think:
Code: [Select]
serverPlay3D(MySound @ getRandom(1,5),%obj.getPosition());Would work instead?
probably with the way torque handles strings however it would be good practice to encase MySound in quotes
otherwise yes

probably with the way torque handles strings however it would be good practice to encase MySound in quotes
otherwise yes
It will work fine, but generally it is good programming practice to encase it with quotes, especially since it won't work in other languages.

It'll work as long as that's the naming scheme of the sounds you want to play.

And yeah, encase MySound in quotes.