Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
[Box2d] One dynamic body bounces and the other dynamic body not — Gideros Forum

[Box2d] One dynamic body bounces and the other dynamic body not

KrakatoaKrakatoa Member
edited April 2014 in Game & application design
Imagine you are programming a breakout game. You got a paddle and a ball.

-The paddle moves in four directions not two.
-The ball bounces in the paddle but the paddle keeps moving with no bounce
-Both objects are dynamic and moves around the world

I thought a way to solve this issue: disable the contact before it occurs using the PRE_SOLVE callback. Now the bounce must be calculed manually obtaining the vector of the bounce and applying it as a linear velocity to the ball.

I read "colllision-anatomy" tutorial from iforce2d. About the normal vector that gives the manifold says: the collision normal does not give you the angle that these fixtures collided at .... it only gives the shortest direction to move the fixtures so that they don't overlap.

That means that the normal can not be used to calcule the bounce manually. I don't know how to calcule the bounce manually.

How would you solve this? Do you know an easier solution that it doesn't need to calcule forces manually?

Comments

  • Hi

    i think if you set the paddle to kinematic instead of dynamic it will also solve your problem. just use linearvelocity to move the paddle

    :)

    Likes: Krakatoa

    +1 -1 (+1 / -0 )Share on Facebook
  • The problem of kinematic it's that doesn't detect collision between kinematics and statics bodies.
  • ok then other solution.

    1) apply very high amount of linear damping to the paddle

    2) create two body for paddle one kinematic and one dynamic and use weld join on both of this body

    :)

    Likes: Krakatoa

    +1 -1 (+1 / -0 )Share on Facebook
  • KrakatoaKrakatoa Member
    edited April 2014
    I chose the second solution and works. What I have made is to make the dynamic body smaller than the kinematic and in the update box2d function i check if there is a kinematic body attached to get it and refresh the position and angle as the dynamic body.

    I doubt if when i make the weldjoint and I refresh the body position in the updatebox2d function the other body should be updated also. I'm doing it manually like this.

    function GameState:updateBox2d()
    world:step(1/60, 10, 5)

    for body, sprite in pairs(actors) do
    if(body.name == "Block") then
    sprite:setPosition(body:getPosition())
    body.object:getKinematicShadow():setPosition(body:getPosition())
    sprite:setRotation((body:getAngle() * 180) / math.pi)
    body.object:getKinematicShadow():setAngle(body:getAngle())
    else
    sprite:setPosition(body:getPosition())
    sprite:setRotation((body:getAngle() * 180) / math.pi)
    end
    end
    end



    Thank you


Sign In or Register to comment.