kodeco.com Forums

# Bullet Physics Tutorial: Getting Started

Learn how to make a simple OpenGL ES Arkanoid game have 3D physics and collision detection in this Bullet Physics tutorial!

This is a companion discussion topic for the original entry at https://www.raywenderlich.com/2606-bullet-physics-tutorial-getting-started

You have several issues in your code:
-One is the way you normalize your speed of the breakout ball.
-The other is related to your border vertex definition. I get AABB issues, like described here:
http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?f=9&t=2818

The first one can be fixed by using the the following way to normalize your speed:

``````btVector3 newVelocity(0,0,0);
btVector3 normalizedCurrentBallDirection(0,0,0);
if(!m_ball->m_body->getLinearVelocity().isZero()){
normalizedCurrentBallDirection = m_ball->m_body->getLinearVelocity().normalized();
}
else if(!m_last_ball_direction.isZero()){
normalizedCurrentBallDirection = -m_last_ball_direction.normalized();
}

newVelocity = normalizedCurrentBallDirection* m_desiredVelocity;
m_last_ball_direction = m_ball->m_body->getLinearVelocity();
m_ball->m_body->setLinearVelocity(newVelocity);
``````

You need to keep the m_last_ball_direction because it might happen that your ball completely stops when hitting a brick. In this case, your way of normalization causes a division by zero error (and mine as well, that is why I check isZero). If the ball stops, we recover its speed by inverting the last known direction and multiplying it by the desired speed.

The other issue I can explain as soon as I have a fix.

Edit: The AABB issue seems to have disappeared, not sure tough if for the better or worse.

This tutorial is more than six months old so questions are no longer supported at the moment for it. We will update it as soon as possible. Thank you! :]