Volume depending on impact force (physics)

0 favourites
  • 3 posts
From the Asset Store
Build a thrilling space station scenario with these level assets and characters.
  • I'm working on physical puzzle, so how do I make impact volume depend on the impact force?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The impulse of a collision is basically the change of velocity from before and after a collision. Using that info you can calculate it. Then you can use lerp or something to map the impulse to a volume.

    Here's one possible conversion:

    lerp(-1000, 0, min(impulse/1000, 1))

    which means when the impulse is 0 the volume will be -1000 dB, and when the impulse is 1000 or higher the volume will be 0 dB. Impulses in between will be between the two volumes. Tweak the numbers for different results.

    global number prevVelocityX=0

    global number prevVelocityY=0

    global number impulse=0

    on sprite collides with wall

    --- set impulse to distance(0,0, sprite.physics.velocityX-prevVelocityX, sprite.physics.velocityY-prevVelocityY)

    --- play sound at volume lerp(-1000, 0, min(impulse/1000, 1))

    every tick

    --- set prevVelocityX to sprite.physics.velocityX

    --- set prevVelocityY to sprite.physics.velocityY

  • Oh, thank you, should've think about the impulse before. Not only velocity before impact was important, that's why it was working incorrect.

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