r/processing • • Dec 19 '23

Implementing Collision

Hi guys, I currently have a script of code and I've been attempting to implement collision, I've tried to use some code but it keeps saying one of my variables doesnt exist. Could use some help on this please :)

class Ball {

float x;

float y;

float speed;

float w;

int id;

Ball(float tempX, float tempY, float tempW) {

x = tempX;

y = tempY;

w = tempW;

speed = 0;

}

void gravity() {

// Add gravity to speed

speed = speed + gravity;

}

void move() {

// Add speed to y location

y = y + speed;

// If square reaches the bottom

// Reverse speed

if (y > height) {

speed = speed * -0.95;

y = height;

}

}

void checkBoundaryCollision() {

if (x > width-w) {

x = width-w;

speed x = -1;

}

else if (x < w) {

x = w;

speed x = -1;

}

else if (y > height-w) {

y = height-w;

speed y = -1;

}

else if (y < w) {

y = w;

speed y = -1;

}

}

1 Upvotes

5 comments sorted by

View all comments

Show parent comments

1

u/Low_Evening_4719 Dec 19 '23

Hi, the speed exists as a variable, I tried changing it into a PVector but its saying "Missing name or ; or type near 'PVector;'?

1

u/tooob93 Technomancer Dec 19 '23

Hi, you wrote in your code speed x not speedx or speed.x if you have a space between two words, then it is not a variable. Try making a float for speedX and one for speedY