Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

d_a_p_a_n03

Bouncing back cube

This topic is 5658 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

I was wondering how one could make a cube move along the screen and once it reached a certain part, it would hit an imaginary wall and bounce back in the other direction. What I did so far is to translate a matrix along the X-axis, and then once the variable, iRotation, which is the variable which moves the cube, got to 10, I did this: if (iRotation == 10) iRotation = -iRotation; But, instead of bouncing back, it starts at the other side of the screen. Any ideas?? Thanx a lot!

Share this post


Link to post
Share on other sites
Advertisement
ok when I do this I have 2 sets of variables, one set that represents where the box is, and one set that represents how much it will move on the next frame. From the sound of your question it sounds to me like you are changing the actual position of the box when you reach an edge. Instead you should change the rate at which the box is moving. so fo instance if you have

if (iPosition == 10 || iPosition == -10) /*When it reaches the boundary*/
iRate = -iRate;


does that make sense? Maybe someone else could explain it a little more clearly

Share this post


Link to post
Share on other sites

  • 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!