I have several circles on the screen, placed on different locations (all dynamic box2d bodies).
I want to add another circle, with an initial velocity of say x, y. I want this body to move freely, as if there’s no gravity. Make all it’s collisions 100% elastic.
I tried setting elasticity to 1, but if I drop it from the top, it doesn’t touch the ceiling again. I want it to just keep moving in the direction it was set to, unless a collision changes its direction.
To explain this further, a simple implementation of what I want would be this, in a square container, with a circular body.
when collides ->
set body.velocityX to -body.velocityX
set body.velocityY to -body.velocityY
Of course this doesn’t work if I have bodies in between.
Suggestions in any language with box2d framework or pseudocode would be appreciated.
In addition to setting the elasticity, you need to set the damping of the body to 0 to eliminate the velocity reduction effect that you’re seeing now.
From the Box2d manual:
Additionally, as mentioned in the manual, damping is not the same as friction… so you’ll probably want to set the friction of the body to 0 as well.