Jump to content
  • Advertisement
Sign in to follow this  
Firecore

Breakout paddle ball bouncing woes

This topic is 3611 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys. Im making a brekout game, but i am having problems making the ball bounce farther away when it touches the ends of one of the paddles. This is my code:
if(paddleCollision(&m_paddlePos))
{
	//now reflect ball
	m_ballPos.y = m_paddlePos.y + m_paddleHeight;
	reflectVec(&m_ballVel, &m_paddleNormal, &m_ballVel);

	if(m_ballPos.x > (m_paddlePos.x + (0.75f * m_paddleWidth)))
	{
		//Hit the right end of the paddle
		m_ballVel.y += 5.0f;
		if(m_ballVel.x > 0.0f)
			m_ballVel.x += 2.5f;
		else
			m_ballVel.x -= 2.5f;
		D3DXVec3Normalize(&m_ballVel, &m_ballVel);
		m_ballVel.x *= m_ballSpeed; 
		m_ballVel.y *= m_ballSpeed;
	}
	else if (m_ballPos.x < (m_paddlePos.x + (0.25f * m_paddleWidth)))
	{
		//Hit the right end of the paddle
		m_ballVel.y += 5.0f;
		if(m_ballVel.x > 0.0f)
			m_ballVel.x += 2.5f;
		else
			m_ballVel.x -= 2.5f;
		D3DXVec3Normalize(&m_ballVel, &m_ballVel);
		m_ballVel.x *= m_ballSpeed; 
		m_ballVel.y *= m_ballSpeed;
	}
}


Basically, what I am trying to do is prevention for when the ball goes up and down, without a real change in velocity. So what I want to do is to make the ball bounce at a greater angle when it collides with the paddle. Anyone got any ideas how i could fix my code?

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!