# Fair Distance

Get help using Construct 2

### » Mon Apr 15, 2013 1:24 pm

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.

Is there is a way to solve it?R0ller2013-04-15 13:26:46
B
4
S
1
Posts: 13
Reputation: 526

### » Mon Apr 15, 2013 1:55 pm

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
Project Lead of Zems Online Card Game

Producer at Impulse Limited
B
18
S
6
G
3
Posts: 677
Reputation: 5,234

### » Mon Apr 15, 2013 5:22 pm

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)
B
4
S
1
Posts: 13
Reputation: 526

### » Mon Apr 15, 2013 5:29 pm

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.
HARMLESS SIGNATURE THAT IS VIEWED BY OTHERS AS OFFENSIVE AND CONTROVERSIAL
B
14
S
3
G
3
Posts: 356
Reputation: 4,377

### » Mon Apr 15, 2013 5:42 pm

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.
B
4
S
1
Posts: 13
Reputation: 526

### » Mon Apr 15, 2013 5:52 pm

What version of Construct 2 do you use?
Play at object
Description: Play audio at an object and track its movement.
HARMLESS SIGNATURE THAT IS VIEWED BY OTHERS AS OFFENSIVE AND CONTROVERSIAL
B
14
S
3
G
3
Posts: 356
Reputation: 4,377

### » Mon Apr 15, 2013 6:06 pm

I have last stable - 119.
I see, it's in beta... i didn't hear they made it.
B
4
S
1
Posts: 13
Reputation: 526

### » Mon Apr 15, 2013 7:46 pm

Well... The good news - it's works. Alot of really cool sound staff in new version. But it's works only in Chrome...
B
4
S
1
Posts: 13
Reputation: 526

### » Mon Apr 15, 2013 7:51 pm

Yeah, the other browsers can go cry in their dirty corner.
HARMLESS SIGNATURE THAT IS VIEWED BY OTHERS AS OFFENSIVE AND CONTROVERSIAL
B
14
S
3
G
3
Posts: 356
Reputation: 4,377

### » Mon Apr 15, 2013 7:52 pm

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)

B
64
S
19
G
8
Posts: 341
Reputation: 12,255

Next