How do I invert this calculation?

0 favourites
  • 4 posts
From the Asset Store
Turquoise Blocks is a game in wich you must drag the pieces to the grid to fill rows or columns to score.
  • I have an explosion which as closer as the object B are, more points will be earned.

    I've established that every 5px closer, 1 point will be added and 200px is the explosions edge. So, in order to do an automatic comparison between these two objects, I came up with this:

    Within 200px radius, I have 40 points (200/5 = 40 points)

    I want to invert this, so I can get the right point measure. So, if I'm 5px close to the explosion, I get 40 points. If i'm 200px far, I get 1 point. If I'm 100px far, I get 20 points and so on

    I'm not good with math so would be nice if someone could help me on that.

  • max points = 40

    radius = 200

    ( radius - distance(objectb.x,objectb.y,explosion.x,explosion.y)) / radius * max points

    for example 200 - 50 = 150 , 150/200 = 0.75 , 0.75 * 40 = 30 points

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • max points = 40

    radius = 200

    ( radius - distance(objectb.x,objectb.y,explosion.x,explosion.y)) / radius * max points

    for example 200 - 50 = 150 , 150/200 = 0.75 , 0.75 * 40 = 30 points

    Thank you. You've saved me.

  • > max points = 40

    > radius = 200

    >

    > ( radius - distance(objectb.x,objectb.y,explosion.x,explosion.y)) / radius * max points

    >

    > for example 200 - 50 = 150 , 150/200 = 0.75 , 0.75 * 40 = 30 points

    >

    Thank you. You've saved me.

    You are very welcome. I'm glad that I could help.

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