Author Topic: Projectile Question  (Read 896 times)

So im trying to make it so when my weapon spawns a projectile, it will randomly play a sound.
I did:
Code: [Select]
function G36KProjectile::onProjectileAdd(%this,%obj)
{
serverPlay3D(Whizz @ getRandom(1,2),%obj.getPosition());
parent::onProjectileAdd(%this,%obj);
}

but i wasnt getting any sound, so then i tried this:
Code: [Select]
function G36KProjectile::onAdd(%this,%obj)
{
serverPlay3D(Whizz @ getRandom(1,2),%obj.getPosition());
parent::onAdd(%this,%obj);
}

Still no sound, is there something im doing wrong? How would i accomplish my goal?

i dont know much about weapons but have you tried parenting it first then adding the line to play sound?

edit: also have you tried using getTransform() ?
« Last Edit: December 19, 2015, 06:47:58 PM by EcstaticEggplant »

You need to parent it before trying to get its position, since it doesn't exist yet. Also, you should do "Whizz" @ getRandom(1, 2)

Still not getting any sound.

Code: [Select]
function G36KProjectile::onProjectileAdd(%this,%obj)
{
parent::onProjectileAdd(%this,%obj);
serverPlay3D("Whizz" @ getRandom(1,2),%obj.getTransform());
}

It's the wrong function. It's just ::onAdd.

Why not just play the sound from the ::onFire function?

Why not just play the sound from the ::onFire function?

Because i want the projectile to be assigned a random looping sound. Its so i can randomize my bullet whizzing sounds.

The thing is though, this sound is just going to be played once from where it was fired and not follow the projectile. serverPlay3D does not follow anything.

The thing is though, this sound is just going to be played once from where it was fired and not follow the projectile. serverPlay3D does not follow anything.
Even if the audio datablock for my sounds is set to loop? AudioClosestLooping

It's still not going to follow the projectile. serverPlay3D does not follow anything.

It's still not going to follow the projectile. serverPlay3D does not follow anything.
What would i have to do in order to make my sound follow the projectile?

As far as I can tell, you'd have to define a new projectile datablock for each sound, changing the default projectile sound property (see Weapon_Rocket_Launcher) for each one. Randomizing the projectile datablock would randomize the sound.

Alternatively, you could use raycast projectiles and play a sound for every nearby client; this would involve checking the shortest distance from every player to a line, so it's probably less efficient than the datablock thing.