This ball goes through the rectangle rather than hitting it or bouncing it

are you there?? Please Help Me

put the code inside the void draw() you made the variable ballx

I know look this is what I did, and the reason why I was getting that error was because you wrote the wrong spelling for ball you wrote balx instead of ballx but also after doing that it is the same as before:

float ballx,bally,xspeed=5,yspeed=8;

void setup() {
size(displayWidth,displayHeight);
stroke(255);
strokeWeight(100);
}

void draw() {
background(0);
point(ballx,bally); //draw the ball
if(sideCollision(ballx)) {
xspeed = xspeed * -1; //reverse horizontal speed
}
if(topOrBottomCollision(bally)) {
yspeed = yspeed*-1; //reverse vertical speed
}
ballx = ballx + xspeed;
bally = bally + yspeed;
rect(810,100,300,75);
rect(mouseX,880,300,75);
if( ballx > 810 || ballx < 1110){
xspeed = xspeed*-1;
}
}

boolean sideCollision(float x) {
if(x<0 || x>width) {
return true;
} else {
return false;
}
}

boolean topOrBottomCollision(float y) {
if(y<0 || y>height) {
return true;
} else {
return false;
}
}

The ball will now bounce between the X sides you have to make the if statement for the Y side as well

You started this conversation in another thread (your first post) and members of the forum responded to you. Since then you have deleted the discussion title and all your comments making the whole conversation useless to anyone wanting to read it.
This is extremely disrespectful to the members who responded and goes against forum etiquette. Please do not do that again here

@yanze03, I also did the other side you ballx and bally but it is still not bouncing on it Here are my codes:

float ballx,bally,xspeed=5,yspeed=8;

void setup() {
size(displayWidth,displayHeight);
stroke(255);
strokeWeight(100);
}

void draw() {
background(0);
point(ballx,bally); //draw the ball
if(sideCollision(ballx)) {
xspeed = xspeed * -1; //reverse horizontal speed
}
if(topOrBottomCollision(bally)) {
yspeed = yspeed*-1; //reverse vertical speed
}
ballx = ballx + xspeed;
bally = bally + yspeed;
rect(810,100,300,75);
rect(mouseX,880,300,75);
if( ballx > 810 || ballx < 1110){
xspeed = xspeed*-1;
}
if( bally > 810 || bally < 1110){
xspeed = xspeed*-1;
}
}

boolean sideCollision(float x) {
if(x<0 || x>width) {
return true;
} else {
return false;
}
}

boolean topOrBottomCollision(float y) {
if(y<0 || y>height) {
return true;
} else {
return false;
}
}

Please Help as Soon as Possible

Continuing the discussion from TfGuy44 (Please Help) - This ball goes through the rectangle rather than hitting it or bouncing it:

@yanze03, I also did the other side you ballx and bally but it is still not bouncing on it Here are my codes:

float ballx,bally,xspeed=5,yspeed=8;

void setup() {
size(displayWidth,displayHeight);
stroke(255);
strokeWeight(100);
}

void draw() {
background(0);
point(ballx,bally); //draw the ball
if(sideCollision(ballx)) {
xspeed = xspeed * -1; //reverse horizontal speed
}
if(topOrBottomCollision(bally)) {
yspeed = yspeed*-1; //reverse vertical speed
}
ballx = ballx + xspeed;
bally = bally + yspeed;
rect(810,100,300,75);
rect(mouseX,880,300,75);
if( ballx > 810 || ballx < 1110){
xspeed = xspeed*-1;
}
if( bally > 810 || bally < 1110){
xspeed = xspeed*-1;
}
}

boolean sideCollision(float x) {
if(x<0 || x>width) {
return true;
} else {
return false;
}
}

boolean topOrBottomCollision(float y) {
if(y<0 || y>height) {
return true;
} else {
return false;
}
}

Please Help as Soon as Possible

you do realise that you just coppied the code for the X-sides and pasted them for the Y-sides?

I suggest you check out:

no i changed it to bally

can you please help me rather than sending links, because i understand better thatway

yes… Bbut you didn’t change the coordinates. you are using the X-axis coordinates for the Y-axis, this will not work

i understand what you are saying, but even the x axis is not working

as in even when it touches the x axis it still goes through.

If you get all the positions right and do it for all sides it should work

if( bally > mouseX || bally < 880){
xspeed = xspeed*-1;
}
how about this

Please reply, I changed the coordinates but it is still not working

Here is the full code, I have 2 rectangles:

rect(810,100,300,75);
rect(mouseX,880,300,75);
if( ballx > 810 || ballx < 1110){
xspeed = xspeed*-1;
}
if( bally > mouseX || bally < 880){
xspeed = xspeed*-1;
}

Get a piece of paper, make a drawing of your game, set your coordinates and variables on the drawing and it will make sence

The rectangle with the mouse will always go wrong in this case, MouseX is a variable this means it will constantly update and change, don’t use 880 but rather: mouseX+300

ok thank you
please stay onlin for 5 mins more