Another math question

vikingviking Member, PRO Posts: 322

I have tried all kinds of ways to make this work, but I am stuck.

My goal is to consistently increase the volume of a sound effect as the distance between the player actor and its target is consistently decreasing.

I have figured out how to constrain my distanceToTarget attribute to get a continuously decreasing number as the player actor approaches the target. However, since the distance between the player actor and target is constantly shrinking as it is getting closer to the target, I can't figure out how to take that shrinking number and make it into a growing number.

At distance 500 the sound effect volume should be 0 and at at distance 0 the volume should be 1.

What do you guys think I should do?

Best Answers

  • EvangelistaEvangelista Posts: 2
    Accepted Answer

    Have you tried:

    Constrain Attribute: game.Audio.Sound Volume to: 1-(game.distanceToTarget/500)

    Cheers

  • SocksSocks London, UK.Posts: 12,822
    edited April 2014 Accepted Answer

    @viking said:
    I have tried all kinds of ways to make this work, but I am stuck.

    Example file:

    Link: https://www.mediafire.com/?jzml0htq37tqtav

    @viking said:
    However, since the distance between the player actor and target is constantly shrinking >as it is getting closer to the target, I can't figure out how to take that shrinking number >and make it into a growing number.

    Simply start with your desired number and take off the shrinking value.

    10 --> 9 --> 8 --> 7 --> 6 --> 5 --> 4 --> 3 --> 2 --> 1 --> 0

    That's going down, but you want it to go up.

    So . . . . just start with ten, and take off this shrinking value.

    10-10 = 0

    10-8=2

    10-7=3

    10-6=4

    10-5=5

    10-4=6

    . . . etc

Answers

  • vikingviking Member, PRO Posts: 322

    Thanks @Evangelista! This does work.

    I also found a different approach, which is to constrain the x position of my actor and divide it by the width of the scene. This works for me because the start position for the actor is always at the very left of the scene and the target is always at the very right of the scene. However, I need your solution in other areas where a shrinking number has to give me an increasing number, so your suggestion is well appreciated :)

  • vikingviking Member, PRO Posts: 322

    Thanks @Socks. This example project is great. The use of magnitude let's me modify the volume with both X and Y transitions, which is great!

Sign In or Register to comment.