Robot Push Game . Two Sprites DISPLACING each other

Student wants Robots to push each other off the stage.
We can displace one but not the other
In the function on line 50 or 51 (?):
function r2hitr1() {
if (robot1.isTouching(robot2)) {
robot1.displace(robot2);
}
if (robot2.isTouching(robot1)) {
robot2.displace(robot1);
}
}
If we switch the IF statements around then the other robot will displace.

Is there a way to get BOTH robots to displace each other so they are “pushing”?

THANK YOU!!

Hi @lkeil,

I took out the isTouching test and associated function. The robots displace each other when their collider boundaries are touched so you don’t need the isTouching.

See the screenshot below.

Michelle

OH my goodness! Thank you so very much! This makes complete sense now that I see it . :star_struck:

Your help is much appreciated!! :slight_smile:

2 Likes