0
votes

I'm developing a simple game much like a brick breaker one.

Now on colliding with bricks, player should rebound, it works fine. But on collision with coins, player shouldn't rebound, coins should disappear.

For this I've tried negative restitution for coins & altered b2MixRestitution like this:

/// Restitution mixing law. Feel free to customize this.
inline float32 b2MixRestitution(float32 restitution1, float32 restitution2)
{
    //return restitution1 > restitution2 ? restitution1 : restitution2;

    float mixRest = 0.0f;
    if(restitution1 > 0.0f && restitution2 > 0.0f)
        mixRest = (restitution1>restitution2)?restitution1:restitution2;
    else
        mixRest = (restitution1<restitution2)?restitution1:restitution2;

    return mixRest;
}

But still player rebounds naturally.

For coins, restitution is -1.00f. For player, restitution is 0.50f.

Is this even possible to have negative restitution for a body in Box2d?

I just want to know if this is possible for two bodies like coins(static) & player(dynamic) that are meant to collide, dynamic one doesn't rebound after a collision.

Can I do this?

2

2 Answers

0
votes

I think you shouldn't use Box2d body for the coins. Use only a sprite. Use some algorithm to detect the collision between player and coin.

For example you could compare the positions of the sprite which is linked to the body of the player and coin sprite..

0
votes

You should set the coin's fixture as a sensor/