Archived

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

the_grip

General Physics Question

Recommended Posts

i have several games i''ve never brought through to completion, so just for a bang (and for a new change of pace) i''m writing a silly little breakout style game. i''m used to creating tile games where physics is not an issue, and it has been some time since i was in school taking physics. Question: how can one determine the physics of the ball''s motion? i.e. when it hits a wall, how to reflect it properly. i have some idea of how this might work, but i''m sure there are tested, tried, and true methods out there for this type of thing. Any advice is appreciated. "You call him Dr. Grip, doll!"

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
how about this?

if ball hit from above or under
ball.velocity.y = -ball.velocity.y

if ball hit from left or right
ball.velocity.x = -ball.velocity.x

Share this post


Link to post
Share on other sites
That sounds good, but don''t i need to track the ball''s position? Or should i determine that from the velocity (if so, how exactly?)? Thanks!

"You call him Dr. Grip, doll!"

Share this post


Link to post
Share on other sites
  
int ball_x; // holds ball''s x coord

int ball_y; // holds ball''s y coord


int ball_velo_x; // velocity incrementer for x coord

int ball_velo_y; // same but for y


ball_x += ball_velo_x; // find new x

ball_y += ball_velo_y; // find new y




Then set a default value for each velocity, then all you do is reverse it''s property (I dunno a word for this) from negative to positive.

Check my site, I got a clone of breakout that you can download and play with. I can send you the semi messy source so you can learn from it.



------------------------------
"I''m a decorated astronaut, I don''t make those kind of mistakes."
"Oh now wait a minute. Look I''ll show ya. I''ll enter the same calculations using what we like to call ''The Right Way''."

-Rem
Zirem Software

Share this post


Link to post
Share on other sites