Author Topic: Sound system (i ned halp)  (Read 6728 times)

For what he's doing, you wouldn't want to use 3d, it wouldn't sound right.

For what he's doing, you wouldn't want to use 3d, it wouldn't sound right.

Err.. why? He's trying to make everyone hear the sound coming from where it was fired, but with a different sound for different distances. 3D works fine for that.

%dist = vectorDist(%shooter.getTransform(), %hearPlayer.getTransform());

You shouldn't use getTransform here. It will work, but it's bad practice. getTransform returns the position and the rotation of an object, you only need the position, so you should be using getPosition.

You shouldn't use getTransform here. It will work, but it's bad practice. getTransform returns the position and the rotation of an object, you only need the position, so you should be using getPosition.
You could use getWords(%wordString,%start,%end) for transform..

You could use getWords(%wordString,%start,%end) for transform..

But that's slower, longer, and less efficient than simply using getPosition.

I know. I was just saying if you would do it that way.

What about %player.getHackPosition()?

getHackPosition is the worst of them all. That one actually does math in Torque to calculate the center point which is completely unnecessary since we're getting the distance between two objects, it'll be the same regardless of whether you use getPosition, getHackPosition, getWorldBoxCenter, or any other method of ascertaining the position.

My entire point was that you never told us what you wanted, so we had no idea how to tell you how to fix your code.

You're gonna need to use a spherical ray search to find nearby players then play a sound to each of them individually. I already explained that one to you here, and the code that I posted later in that topic can easily be adapted to work in this function.

Once you've found a player, to calculate the distance between it and %obj use %dist = vectorDist(%shooter.getTransform(), %hearPlayer.getTransform());

Then you have to play the sound in 3d to the player. Once you found the player, use %foundPlayer.client.play3D( sound profile, %obj.getTransform()) to play a sound on it.
Now in my function
Code: [Select]
%dist = vectorDist(%shooter.getTransform(), %hearPlayer.getTransform()); is that how i define the distance or would this operation only fit in differently written function (if you understand what im saying). Actually let me just show you what i did

function ARX160Image::onFire(%this, %obj, %slot)
{
   initContainerRadiusSearch(%this.getPosition(), $TypeMasks::PlayerObjectType, %this);
    while(%obj = containerSearchNext());

    if(%dist = vectorDist(%shooter.getTransform(), %hearPlayer.getTransform()) < 50)
      ServerPlay3D(ARX160Fire,%obj.getPosition());
     else if(%dist = vectorDist(%shooter.getTransform(), %hearPlayer.getTransform()) < 100)
      ServerPlay3D(ARX160Med,%obj.getPosition());
     else
      ServerPlay3D(ARX160Long,%obj.getPosition());



Questions with the function are color coded:
Is this how i do it?
After defining %Dist, is this operation compatible?
Did i do this right?

Pretty much none of that is correct, but that's okay.

Code: [Select]
function ARX160Image::onFire(%this, %obj, %slot) {
    initContainerRadiusSearch(%obj.getPosition(), $TypeMasks::PlayerObjectType, %obj); // %obj is the player, not %this
    while(%player = containerSearchNext()) {
        if(!isObject(%player.client))
            continue; // ignore bots
        %dist = vectorDist(%obj.getPosition(), %player.getPosition());
        if(%dist < 50)
            %player.client.play3D(ARX160Fire, %obj.getPosition());
        else if(%dist < 100)
            %player.client.play3D(ARX160Med, %obj.getPosition());
        else
            %player.client.play3D(ARX160Long, %obj.getPosition());
    }
}

Pretty much none of that is correct, but that's okay.

Code: [Select]
function ARX160Image::onFire(%this, %obj, %slot) {
    initContainerRadiusSearch(%obj.getPosition(), $TypeMasks::PlayerObjectType, %obj); // %obj is the player, not %this
    while(%player = containerSearchNext()) {
        if(!isObject(%player.client))
            continue; // ignore bots
        %dist = vectorDist(%obj.getPosition(), %player.getPosition());
        if(%dist < 50)
            %player.client.play3D(ARX160Fire, %obj.getPosition());
        else if(%dist < 100)
            %player.client.play3D(ARX160Med, %obj.getPosition());
        else
            %player.client.play3D(ARX160Long, %obj.getPosition());
    }
}
*sigh* i was hoping to get it right. Thanks for all the help i appreciate it. Is there anything else i should know regarding this?

so i ran into a problem, i put that function in
Code: [Select]
function ARX160Image::onFire(%this, %obj, %slot){

initContainerRadiusSearch(%obj.getPosition(), $TypeMasks::PlayerObjectType, %obj); // %obj is the player, not %this
    while(%player = containerSearchNext()) {
        if(!isObject(%player.client))
            continue; // ignore bots
        %dist = vectorDist(%obj.getPosition(), %player.getPosition());
        if(%dist < 50)
            %player.client.play3D(ARX160Fire, %obj.getPosition());
        else if(%dist < 100)
            %player.client.play3D(ARX160Med, %obj.getPosition());
        else
            %player.client.play3D(ARX160Long, %obj.getPosition());
    }
}

And when i put it in, it breaks a function like 20 lines above it. Line 340. Anyone know why?

You'll need to post the part of the script where the error occurs (preferably just the entire file).

Alright ill update the Topic with the gun, see if you guys can fix the problem.


It doesn't need to be.

Er, I did notice a mistake I made though. I forgot to define a size of the radius for the search. So you'll need to change the line that says

initContainerRadiusSearch(%obj.getPosition(), $TypeMasks::PlayerObjectType, %obj); // %obj is the player, not %this

To something like this:

initContainerRadiusSearch(%obj.getPosition(), 150, $TypeMasks::PlayerObjectType, %obj); // %obj is the player, not %this
« Last Edit: October 11, 2014, 06:43:13 PM by $trinick »