Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Pong - ball hit, and recoil formula.  (Read 1643 times)
0 Members and 1 Guest are viewing this topic.
Offline Mads

JGO Ninja


Medals: 26
Projects: 3
Exp: 6 years


One for all!


« Posted 2010-09-01 17:12:56 »

I'm just making your regular pong game. I came to a point where I need to calculate how the ball needs to fly after it hit a pad.
Any ideas?

Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 841
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #1 - Posted 2010-09-01 17:16:01 »

It depends.


If you want it quick-and-dirty (how most pong games work): simply flip xVelocity.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social
Offline SimonH
« Reply #2 - Posted 2010-09-01 17:59:11 »

If you want it quick-and-dirty (how most pong games work): simply flip xVelocity.
Yeah, that's what I'd do, with a little nudge on yVelocity based on the speed of the bat.

People make games and games make people
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 841
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #3 - Posted 2010-09-01 18:02:09 »

Watch the very first pong game...
http://www.youtube.com/watch?v=XNRx5hc4gYc
From the looks of it, it's STILL the best with those funny physics!

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social
Offline Mads

JGO Ninja


Medals: 26
Projects: 3
Exp: 6 years


One for all!


« Reply #4 - Posted 2010-09-01 18:21:53 »

It depends.


If you want it quick-and-dirty (how most pong games work): simply flip xVelocity.

Thats all? The ball would fly back and forward in the same track forever? Did I miss something?

Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 841
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #5 - Posted 2010-09-01 18:32:11 »

Combine my suggestion with Simon's and you have a less predictable path.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social
Offline SimonH
« Reply #6 - Posted 2010-09-01 23:35:36 »

Thats all? The ball would fly back and forward in the same track forever? Did I miss something?
If you want the real deal google 'reflection vectors' - but IMHO it's overkill for pong!

People make games and games make people
Offline Matzon

JGO Knight


Medals: 19
Projects: 1


I'm gonna wring your pants!


« Reply #7 - Posted 2010-09-02 04:34:52 »

also nudge direction based on how far of the center of the bat - else it wont ever do anything but up and down Smiley

Offline Mads

JGO Ninja


Medals: 26
Projects: 3
Exp: 6 years


One for all!


« Reply #8 - Posted 2010-09-04 08:51:57 »

Thanks for your replies. I have thought of a way but I'm unsure about some formulas:
I have taken time, and speed out of the picture completely! I want the ball to hit the pad and go in the direction it hit the pad in.
For example, it hits the buttom of the pad - the ball turns and goes 45 degrees (south). Or if it hits the middle of the pad it would go straight 90 degrees from the pad.

How do I detect where the ball hits and then apply that to the balls curve? What formulas should I use?
I need to detect where the pad is, and where the ball (x-coord) was when it hit the pad right?

Offline ryanm

Senior Devvie


Projects: 1
Exp: 15 years


Used to be bleb


« Reply #9 - Posted 2010-09-04 09:26:49 »

Ok, so you're disregarding the ball's incoming velocity and the pad velocity - the ball's outgoing direction depends solely on where it hits the pad.

Assuming you know:
  • The ball center y-coordinate - by
  • The ball x-velocity - bvx
  • The pad center y-coordinate - py
  • The pad size - ph

The ball velocity after striking the pad will be (-bvx, (by - py) / ( ph / 2 ) * bvx )
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (35 views)
2014-12-15 09:26:44

Mr.CodeIt (26 views)
2014-12-14 19:50:38

BurntPizza (60 views)
2014-12-09 22:41:13

BurntPizza (95 views)
2014-12-08 04:46:31

JscottyBieshaar (55 views)
2014-12-05 12:39:02

SHC (71 views)
2014-12-03 16:27:13

CopyableCougar4 (73 views)
2014-11-29 21:32:03

toopeicgaming1999 (133 views)
2014-11-26 15:22:04

toopeicgaming1999 (124 views)
2014-11-26 15:20:36

toopeicgaming1999 (34 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!