Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Any way to detect the force of a collision pre-solve??? — Gideros Forum

Any way to detect the force of a collision pre-solve???

larflarf Member
edited February 2013 in General questions
Is there a way to determine the force of a collision pre-solve???
I have a bouncy ball in my scene.
I want it to make a little bouncy sound when it hits the ground if the force is greater than a certain amount.
I know I can do this with Event.POST_SOLVE listener and Event.maxImpulse, but the sound effect sounds a bit late if I do that.

Is there anyway to determine the "maxImpulse" or force of a collision pre_solve?
Or does anyone have any other ideas?

Comments

  • ar2rsawseenar2rsawseen Maintainer
    edited February 2013 Accepted Answer
    There is no "native" way to do that, but you can estimate the impulse by multiplying mass with velocity, thus:
    local impulse = body:getMass()*body:getLinearVelocity()
  • Is that all that box2d does when it determines the force of the collision? I guess it doesn't really matter, that should be good enough for my situation. Thanks for the suggestion @ar2rsawseen !
  • Well don't know how exactly box2d does that, but what I suggested is the simple formula from physics.
    And yes, basically you'd need some relative values, so it should be more than enough :)
  • larflarf Member
    edited February 2013
    Yeah, looks like Box2d takes more into account when calculating the impulse for a collision because I'm getting different values. But that's fine, these vals still work for me.

    I'm still noticing a bit of lag from when the pre-collision event occurs to when I actually hear the sound effect. I've chopped all the dead space out of the begining of my sound effect .wav file so that shouldn't be a problem.
    I suspect the lag is coming from gideros loading and playing the file. Any thoughts?
  • @larf you should preload the sounds as create an object
    sfx = Sound.new("mysound.wav")
    And then only play it on the collision
    sfx:play(0, false)

  • @ar2rsawseen I've been doing that. I guess i shouldn't have said loading, just playing the sound file seems to lag a bit.

    There are a few different sounds I want the ball to make so I'm thinking about putting all the sound effects for the ball into one .wav file then pausing/unpausing and skipping forward/back in the .wav file for the different sounds.
  • @larf I don't think that it would be a better solution.

    Could you check this project and see if you have the same problem?

    https://github.com/ar2rsawseen/GameTemplateOld

  • @ar2rsawseen I see what you've done in your project.
    The sound still seems to be a bit lagged to me.
    Maybe I'm just being a bit too picky.
    I'll figure something out.
    Thanks for the help.
  • There is also newer version of template, that I try to keep updating:
    https://github.com/ar2rsawseen/GameTemplate

    Oh, and of course latency may depend on which version of Gideros you are using.
    I think sound latency was improved after 2012.09.05 version
Sign In or Register to comment.