Volume depending on impact force (physics)

Just started using Construct 2? Post your questions here

Post » Sat Apr 09, 2016 10:19 pm

I'm working on physical puzzle, so how do I make impact volume depend on the impact force?
B
9
S
1
Posts: 14
Reputation: 459

Post » Sat Apr 09, 2016 11:55 pm

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
B
92
S
32
G
110
Posts: 5,298
Reputation: 71,507

Post » Sun Apr 10, 2016 12:22 am

Oh, thank you, should've think about the impulse before. Not only velocity before impact was important, that's why it was working incorrect. :)
B
9
S
1
Posts: 14
Reputation: 459


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 1 guest