Legacy GM Collision Issues in Pong Clone

A

Anti-Icarus

Guest
For a few months, I was working on a Pong clone as shown by the following screenshot:

Pong clone screenshot.png

I created it using the drag and drop method due to its simplicity. I have it basically working with the intention of putting in a few more tweeks to the gameplay. Now I have come across a few collision issues with the ball. As you can see in the screenshot, the game consists of two vertical rectangles that are paddles and the square ball. I set up the ball so that it would collide on the two paddles just like in the original Pong. When it collides with the left paddle, it moves freely in the direction of obj_Paddle1.y-y at the speed of 10. When it collides with the right paddle, it moves freely in the direction of 180+obj_Paddle2.y-y at the speed of 10. When it collides on either the top or bottom walls, it bounces precisely against them as solid objects.

During my play tests, I've encountered two issues regarding the collision of the ball, which may be more likely because that it's in the shape of a square. Sometimes, the ball just endlessly bounces up and down between the top and bottom walls. At other times, the ball and a paddle become frozen in position when the former collides on the top or bottom part of the latter. I can assume that it can be resolved easily by changing the ball's sprite from a square to a circle. Would that be sufficient enough?
 
C

ConsolCWBY

Guest
At other times, the ball and a paddle become frozen in position when the former collides on the top or bottom part of the latter. I can assume that it can be resolved easily by changing the ball's sprite from a square to a circle. Would that be sufficient enough?
Not always. It would depend on the collision mask (you can change that and see if a sphere would be better without changing the sprite). Anyway, detecting if the ball is in a loop state isn't too hard. It's discussed in the beginner tutorials on the GM:S front end. Did you take a look at any of it?
 
A

Anti-Icarus

Guest
I just changed the collision mask of the ball sprite to a sphere. It seemed to resolve the issue of the ball getting stuck on the paddles and was able to keep the game going on for more than 3 to 4 rounds. However, I have just encountered the issue of the ball bouncing back and forth between the top and bottom walls after 13 rounds. As of this writing, I still have the game running and the ball is currently stuck in the endless loop.
 
A

Anti-Icarus

Guest
Just so that I'm clear, my Pong clone has been working the way it's supposed to work. The real problem I'm currently experiencing happens when the ball gets created in the middle of the playfield and ends up bouncing up and down between the two walls. The following screenshot explains it best:

Pong game breaking bug screenshot.png

What I'm trying to do here is to make the ball bounce consistently in both directions of the playfield every time it gets created without getting stuck in a bouncing loop which would break the game. Based on the angle system, the ball should not be able move either 90 degrees or 270 degrees directly every time it gets created. When that happens, the ball gets stuck in a bouncing loop and breaks the game.
 
J

jackhigh24

Guest
whats the code you aare using for setting it off in a direction as you can just put if not what ever direction around it and if it is then do an else this direction.

EDIT
your using drag and drop, i dont know any drag and drop so not sure if this would help, add a create event to the ball object and put in it
Code:
if direction == 90 || direction == 270
{
direction = choose(88,92,268,272);
}
 
Last edited by a moderator:
A

Anti-Icarus

Guest
whats the code you aare using for setting it off in a direction as you can just put if not what ever direction around it and if it is then do an else this direction.

EDIT
your using drag and drop, i dont know any drag and drop so not sure if this would help, add a create event to the ball object and put in it
Code:
if direction == 90 || direction == 270
{
direction = choose(88,92,268,272);
}
I tried the code in the Create event and it didn't make much difference. Now in order to paint a clearer picture here, I made the ball a solid object and have its events set up like this:

2016-08-11_18h40_31.png

In the Create event, I set Alarm 0 to 90 (before I added the code from earlier). This means that after 90 steps (3 seconds) of the ball's creation, it would move freely in the direction of random(180) at the speed of 10. As I have stated earlier, the ball moves also moves freely in the directions of obj_Paddle1.y-y and 180+obj_Paddle2.y-y at the speed of 10 after colliding respectively with obj_Paddle1 and obj_Paddle2 (paddles respectively representing Player 1 and Player 2). When it collides with a wall (obj_Wall), it bounces precisely against solid objects as shown here:

2016-08-11_20h13_26.png

And when the ball moves outside of the room, this happens:

2016-08-11_20h01_28.png

In layman's terms, player 2 scores when the ball leaves the room on the left side and player 1 scores when it leaves on the right side. The Alarm 1 event creates the ball 3 seconds after it leaves the room, thus beginning a new round. That event's Create Instance action works like this:

2016-08-11_18h41_07.png

Unless the ball gets stuck in the bouncing loop I've been referring to, this drag-and-drop code does what it's supposed to do.
 

Attachments

J

jackhigh24

Guest
ok like i said i dont use or know drag and drop as its easier to learn GML than try and make drag and drop do anything properly, so you say your setting it to choose a random from 180 at speed 10 after 3 seconds of being created, so i guess your setting that in the alarm, so ok try this, right after what ever thing you use to pick set that direction grab an execute code from the control items and put that code i gave you in there and drop it into the actions list right after that bit that creates it, this should change the direction then, other than that you will have to wait for someone that uses drag and drop to help but most on here tend to only do gml.
 

Genetix

Member
Another way to go, every time their is a collision with the ball and wall have the ball: direction += random_range(-3,3)

That will create a subtle bounce in another direction every time the ball hits a wall, it will never get stuck again - also feels good, try it out and see for yourself!
 
Top