Skip to main content
gamedev.net
🔒 Locked

help

Started by Genius_Bobby Nov 1, 2004 at 7:02 AM 1 replies 700+ views
Original Post
Genius_Bobby
Genius_Bobby
Hi, i am moving the ball along x-axis and y a-xis,but after hitting the top wall its coming back exactly with the same position.suppose asterisk as ball hitting top wall and line as a top wall -------------------------------------------------- * * * * * * * * * * * * (ball moving upward) (ball moving downward) Idle function i m using idlefunc() { x=0.0; y=0.0; x += f * speed; y += a * speed; } when the programme will call the idle function ball will hit the top wall but after hitting top wall it have to change the direction with certain angle. the function i m using is if (x+y > e) //e is the top wall { vf = -vf; a = -a; } why its not changing the direction of ball? after hitting the topwall it have to hit the right wall instead of hitting bottom wall. i use visual C++ and opengl glut library to do this programme.
BEHOLDER192875
BEHOLDER192875
Change only the y direction to be the opposite for the vector's direction. If you change the x direction too it will just return the same direction it came from. Additionally, if the ball hits the wall at a 90 degree angle, it will just bounce between the top and bottom walls.

If your confused about the concept of vectors there are plenty of books out there, or you could just pick up a book on calculus.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.