This site requires JavaScript, please enable it in your browser!
Greenfoot back
thetrambini
thetrambini wrote ...

2017/5/2

Collision not working

thetrambini thetrambini

2017/5/2

#
I am trying to make a pong-like game in greenfoot, but this if loop isn't working:
if (getOneObjectAtOffset(0, 0, ball.class) == getObjects(paddle_right.class)|| getOneObjectAtOffset(0,0,ball.class) == Greenfoot.getObjects(paddle_left.class)) {
           bounce();
    }
It is written in a ball item which is an actor.
danpost danpost

2017/5/2

#
The ball will never (or at least, should never) intersect another ball. So, why would you try to get balls at an offset from where a ball is located? Try this:
if (isTouching(paddle_right.class) || isTouching(paddle_left.class)) {
    bounce();
}
You need to login to post a reply.