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
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) 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
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