Fair Distance

0 favourites
  • 13 posts
  • Hello guys!

    I have little problem here.

    i need to calculate real distance to the object in real time. And the distance to the origin point is not actually right.

    <img src="http://s003.radikal.ru/i201/1304/34/2fcd3627599e.png" border="0" />

    Is there is a way to solve it?

  • If the origin point is exactly at the center of the object...

    OriginPoint.X - OriginPoint.Width/2 - Player.X

    OriginPoint.Y - OriginPoint.Height/2 - Player.Y

  • Thanks!

    But, can u plz tell me a little more details how to make it work?

    Generally, i trying to make a sound in my game. I found the way to make the volume change depending of distance between object and player.

    I'm using this formula:

    System every tick -> Set volume(-distance(player.X, Player.Y, Sound.X, Sound.Y)/10 dB)

    It works fine for small objects. But now i have a big object, and i want to hear some sound arround it. And also i want make that sound fade in/out depending from player's moves.

    And in this case my old formula doesnt work. Sound's volume going up if player moves closer to the center. But i need same volume arround whole object. And fade it only if player going away

    Sorry for my engl)

  • Why don't you use sound at position or something? It is an action that plays sound that is fixed to some object you defined, and if you are far away from the object the sound is quieter. I think so.

  • Hm...

    Where exacly can i find that "sound at position"?

    In audio actions C2 has pretty few options, and this not one of them for sure.

    Maybe i missing something.

  • What version of Construct 2 do you use?

    Advanced: Positioned sound

    Play at object

    Description: Play audio at an object and track its movement.

  • I have last stable - 119.

    I see, it's in beta... i didn't hear they made it.

  • Well... The good news - it's works. Alot of really cool sound staff in new version. But it's works only in Chrome...

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Yeah, the other browsers can go cry in their dirty corner.

  • If you are using this expression to determine the volume:

    System every tick -> Set volume(-distance(player.X, Player.Y, Sound.X, Sound.Y)/10 dB)

    and you want the volume to be affected by the size of the sprites, why don't you subtract half the width of the sprite from the distance. Something like this:

    System every tick -> Set volume((-distance(player.X, Player.Y, Sound.X, Sound.Y)-(sound.width/2))/10 dB)

  • Well... The good news - it's works. Alot of really cool sound staff in new version. But it's works only in Chrome...

    Oh, i was a little blinded by cool staff there. But generally "play at object" doesn't solve the problem, becouse it still working around origin point. And also it makes panning sound around that point.

    So, i still hear sound from center of the object, not from whole object..

    It's like we have a river, but sound of water going just from center of it.

  • If you are using this expression to determine the volume:

    System every tick -> Set volume(-distance(player.X, Player.Y, Sound.X, Sound.Y)/10 dB)

    and you want the volume to be affected by the size of the sprites, why don't you subtract half the width of the sprite from the distance. Something like this:

    System every tick -> Set volume((-distance(player.X, Player.Y, Sound.X, Sound.Y)-(sound.width/2))/10 dB)

    Well, i get the idea but i'm too stupid to make it work...

    System every tick -> Set volume((-distance(player.X, Player.Y, Sound.X, Sound.Y)+(sound.width/2))/10 dB)

    Something like that works nice, if the object is square. But if it's not?... Player can come to the object from any side. And the object isn't square.

  • It's more like the object is a circle, with the radius of the circle being half the sprite's width. I can see this possibly being a problem if there is a huge differences between the sprite's width is the sprite's height. If that's the case, you might want to consider adding a few image points around the sprite, and setting the sound volume based on the distance between the player and the sprite's closest image point. However, if your sprite's width is remotely close to its height, this shouldn't be necessary.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)