Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (133)
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  
  [LibGDX]Trying to make Pong, weird ball behaviour, slides on wall?  (Read 487 times)
0 Members and 1 Guest are viewing this topic.
Offline ericblobb

Junior Newbie





« Posted 2014-08-20 22:09:26 »

Here's the project on GitHub: http://github.com/ericblobb/PongHelp

Whenever I run the game and the ball hits a wall, instead of bouncing off like it's supposed to do, it sticks to the wall and slides on it. And that's only for the top wall. For the bottom wall, the ball slides for less than second then drops off the window. I have no idea at what is happening so could any of you guys help?

Thanks.
Offline thedanisaur
« Reply #1 - Posted 2014-08-20 22:15:00 »

You never change isGoingRight or isGoingLeft in bouncewall

edit: the issue probably has to do with ball.overlaps

Every village needs an idiot Cool
Offline Longarmx
« Reply #2 - Posted 2014-08-20 22:18:45 »

You never change isGoingRight or isGoingLeft in bounce wall

That's because there's no right or left wall  Wink

@OP Using booleans to represent the direction of the ball, and then translating it to x & y seems really clunky. Instead (since you are using LibGDx), use a Vector2 to represents the ball direction. When a ball hits either the top or bottom wall, just invert the y component of the vector. Really, now that I think about it, just use an dx and dy value to represent the velocity if you don't want to use vectors.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline thedanisaur
« Reply #3 - Posted 2014-08-20 22:20:30 »

Yeah, for what ever reason I was thinking of breakout

edit:

Maybe I should elaborate. Basically if you overlap the top wall with the ball and the ball moves over the top wall more before you check to see if it overlaps then you'll change direction, but will still be overlapping the wall.

This will in turn make the ball "ping-pong" back and forth along the wall forever, constantly changing direction but never reaching a point where the ball no longer overlaps the wall. I suggest you put breakpoints in your if statements in bouncewall() to see if it keeps alternating, then go from there.

Every village needs an idiot Cool
Offline ericblobb

Junior Newbie





« Reply #4 - Posted 2014-08-20 22:54:26 »

@OP Using booleans to represent the direction of the ball, and then translating it to x & y seems really clunky. Instead (since you are using LibGDx), use a Vector2 to represents the ball direction. When a ball hits either the top or bottom wall, just invert the y component of the vector. Really, now that I think about it, just use an dx and dy value to represent the velocity if you don't want to use vectors.
This sounds like a good idea but I've never used vectors before Do you know any good tutorials or references that I can look into? Also thanks for the other replies everyone. I'll try to take into account what you all said.
Offline Longarmx
« Reply #5 - Posted 2014-08-20 23:08:02 »

snip
This sounds like a good idea but I've never used vectors before Do you know any good tutorials or references that I can look into? Also thanks for the other replies everyone. I'll try to take into account what you all said.

I was just suggesting vectors for a container for the x & y values of the velocity. For aligned objects like your walls, simply reflecting the y (y = -y) will give you the reflection you need. Like danisaur said, your collision detection might be running more than once, which is causing it to "jitter" like you described. Read his post for more info.

Offline Gibbo3771
« Reply #6 - Posted 2014-08-21 10:50:15 »

It is because the ball is overlapping and staying overlapped.

So therefore the code that resolves the collision is getting called repeatedly.

Have a search for Minimum Translation Distance or Minimum Translation Vector, this is what you will be looking for to do proper collision resolving using an easy algorithm.

EDIT: For more complex shapes, you can look up Separating Axis Theorom.

"This code works flawlessly first time and exactly how I wanted it"
Said no programmer ever
Pages: [1]
  ignore  |  Print  
 
 

 

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 (38 views)
2014-12-15 09:26:44

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

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

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

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

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

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

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

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

toopeicgaming1999 (38 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!