.com.unity Forums
  The Official e-Store of Shrapnel Games

This Month's Specials

Air Assault Task Force- Save $8.00
Bronze- Save $10.00

   







Go Back   .com.unity Forums > Shrapnel Community > Space Empires: IV & V

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #7  
Old September 12th, 2003, 11:27 PM
Suicide Junkie's Avatar
Suicide Junkie Suicide Junkie is offline
Shrapnel Fanatic
 
Join Date: Feb 2001
Location: Waterloo, Ontario, Canada
Posts: 11,451
Thanks: 1
Thanked 4 Times in 4 Posts
Suicide Junkie is on a distinguished road
Default Re: OT: would anyone happen to know how to calculate bouncing a ball off an angled box?

Neglecting corner hits;

1) You want to know the relative angles between wall and ball. All arithmetic is modulo 360 degrees. (359 + 1 = 0)
2) We can rotate the coordinates by minus the wall angle. This makes the wall look like zero, and the ball will be ball_angle - wall_angle.
You want to reflect in the plane of the wall.
Taking 90 degrees off it, then taking the negative, and adding the 90 degrees back.
85-90 =-5, -5 -> +5, 5+90 = 95 (check)
224 -90 = 134, 134 -> -134 (or 226), 226+90 = 316 (check)
3) Restore the original coordinates by adding back the wall's angle.

So:
NEW_ANGLE = ((((OLD_ANGLE-90-WALL_ANGLE)*-1)+90+WALL_ANGLE) +360) % 360

Where % = modulo operator in whatever programming language you use.
360 is added before the modulo operation because to ensure the resulting value is positive. (Some programming Languages deal with modulo of negative numbers differently)

-----
For Corner Hits:
The effective plane that the ball is bouncing off of is perpendicular to the line connecting the center of the ball to the corner.
Reply With Quote
 

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 05:09 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©1999 - 2025, Shrapnel Games, Inc. - All Rights Reserved.