Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

2D All the way! / Bouncing off the walls

Author
Message
The Game Programmer
21
Years of Service
User Offline
Joined: 4th Dec 2004
Location: Sitting, and waiting, and staring, and..
Posted: 12th Mar 2005 10:36
Starting a new project after I found out my old one was too complicated. This one is currently codenamed: Pixie. I want to have circles (2d) bouncing off a wall (2d), how do I find out the angles and make it bounce at that angle.

Well, I'm trying aren't I.....

When Life gives you lemons make orange juice. Then sit back and wonder how it was done.
Monsieur Mort
21
Years of Service
User Offline
Joined: 12th Feb 2005
Location:
Posted: 12th Mar 2005 23:54
You need to store, for each circle, a horizontal speed and a vertical speed. Lets call them hs# and vs#. When the ball hits a horizontal wall, you need to reverse vs# (
), and when the ball hits a vertical wall you need to reverse hs# (
). If you want the walls to be at different angles it gets a bit more complicated. To move the circles you just need to add hs# to their x-position and vs# to their y-position.

Why do you sink I ave zees outRAGEOUS accente?!
Robot
22
Years of Service
User Offline
Joined: 27th May 2004
Location:
Posted: 15th Mar 2005 03:25
would it not be if it hits a horizontal wall you reverse the horizontal speed and not the vertical speed

The happenings of tommorow are behind us now
Monsieur Mort
21
Years of Service
User Offline
Joined: 12th Feb 2005
Location:
Posted: 21st Mar 2005 05:13 Edited at: 21st Mar 2005 05:23
[edit] no I can't make it look good, and I don't have webspace to post a pictorial explanation. Try to think about it: draw a horizontal line and a ball above it. Now imagine the balling moving downward and to the right. When the ball hits what does it do? Well it bounces up and continues to the right, so what you do is reverse the vertical motion and leave horizontal motion as it is. [/edit]

Why do you sink I ave zees outRAGEOUS accente?!
Monsieur Mort
21
Years of Service
User Offline
Joined: 12th Feb 2005
Location:
Posted: 21st Mar 2005 05:17
Ok, that illustration would have been better if Apollo didn't automatically erase whitespace. Hang on, I'll try to fix it

Why do you sink I ave zees outRAGEOUS accente?!
Robot
22
Years of Service
User Offline
Joined: 27th May 2004
Location:
Posted: 23rd Mar 2005 03:55 Edited at: 23rd Mar 2005 04:21
I was thinking more along the lines of this image



[edit] gaaa thats vertical you are entirely right i take back everything i said.

The happenings of tommorow are behind us now
Baggers
22
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 27th Mar 2005 08:00
If you would be ok doing it in vectors i can give you the code for that ?

Login to post a reply

Server time is: 2026-07-14 00:28:10
Your offset time is: 2026-07-14 00:28:10