The Daily Click ::. Forums ::. Klik Coding Help ::. Realistic bouncing
 

Post Reply  Post Oekaki 
 

Posted By Message

Radix

hot for teacher

Registered
  01/10/2003
Points
  3139

Has Donated, Thank You!VIP MemberGOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!GOTW WINNER CUP 4!
7th October, 2003 at 20:07:21 -

Hoi, I'm trying to make a game based (very, very) loosely on Arkanoid. In fact, the only similarity it has to arkanoid is the ball and paddle. However, my paddle can rotate around it's axis to change the angle of the shot, and I'm afraid the ball may be to small for an accurate bounce angle based on fine collision.

Anyway, since I'm failing maths, I was wondering if anyone had any insight on how to make it bounce properly, perhaps using the animation direction of the paddle.
Part of the problem is that because the paddle rotates 360, it's possible to hit the ball off of the back.

Image Edited by the Author.

 
n/a

ShadowCaster

Possibly Insane

Registered
  02/01/2002
Points
  2203
7th October, 2003 at 22:02:46 -

If you take the normal of the bat, then the angle the ball bounces at will be the angle that it hit at, only reversed around that normal.

So, if your bat is facing direction 6 and the ball is traveling in direction 20 when it collides, then it will reflect at direction 12.

Though there are going to be problems with something this simple, for example, if it hits the side of the bat rather than the face then your going to have problems unless you code that in (which is going to be difficult.

But it's up to you, if you want to put that much work into it. You can probably get away without coding it, because "normal" people will use the main part of the bat instead of trying to be trickey, but it still may happen by accident.

Mike

 
"Now I guess we're... 'Path-E-Tech Management'" -Dilbert

Radix

hot for teacher

Registered
  01/10/2003
Points
  3139

Has Donated, Thank You!VIP MemberGOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!GOTW WINNER CUP 4!
7th October, 2003 at 22:09:26 -

Ah, yes. That way, it won't matter whether it hits the front or back. Thanks.

I'll probably just make the paddle's hitzone only 1px high so I don't have to worry about corners.

 
n/a

Assault Andy

Administrator
I make other people create vaporware

Registered
  29/07/2002
Points
  5686

Game of the Week WinnerVIP Member360 OwnerGOTM JUNE - 2009 - WINNER!GOTM FEB - 2010 - WINNER!	I donated an open source project
8th October, 2003 at 03:11:45 -

If you want the ball to go the exact direction of the bat when it hits, and your bat uses 360^ motion and so does your ball, use some trigonometrey:

Ball collides with Bat - Ball.alt a = Bat(angle)

always - X.Ball = X( "Ball" ) + 10 * Cos( Alterable Value A( "Ball" ) )
always - Y.Ball = Y( "Ball" ) + 10 * Cos( Alterable Value A( "Ball" ) )

-Andy

 
Creator of Faerie Solitaire:
http://www.create-games.com/download.asp?id=7792
Also creator of ZDay20 and Dungeon Dash.
http://www.Jigxor.com
http://twitter.com/JigxorAndy

Radix

hot for teacher

Registered
  01/10/2003
Points
  3139

Has Donated, Thank You!VIP MemberGOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!GOTW WINNER CUP 4!
8th October, 2003 at 05:17:57 -

Thanks, I figured out a simple solution for the correct angle using 32 directions.

With the paddle animation skewed 90 degrees (so that direction zero looks like dir eight):
Ball direction = Dir( "Paddle" ) - ( Dir( "Ball" ) - Dir( "Paddle" ) )

That seems somewhat redundant to me, but it works perfectly so I'm not going to bother fiddling with it.

 
n/a
   

Post Reply



 



Advertisement

Worth A Click