Collision For a JS Game Not Working Properly | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Collision For a JS Game Not Working Properly

I'm working on a small game, just to test out collision and some other new concepts I learned in my course. I added a traffic cone to the game as a barricade, and have been trying to add collision to it for a few days. Today, I finally made a breakthrough with it, but for some reason, it only works when the cone is bumped into from the left. Please help! https://www.sololearn.com/compiler-playground/Wb4LvBYI9HfU

8th Feb 2023, 2:03 AM
Benny H
Benny H - avatar
2 Answers
+ 3
Because when the conditions of the outer if are true, all the inner ifs are also true. The value of restrictMovement will be overridden by the last if statement, thus always be either 4, or 0 when the outer conditions are not met. Btw, your current collision logic allows the images of the scout and the cone slightly overlap, which might not be intended.
8th Feb 2023, 4:14 AM
Lochard
Lochard - avatar
0
I am aware of the issue with the scout overlapping, but I wasn't with the if statements. Thank you!
8th Feb 2023, 7:54 PM
Benny H
Benny H - avatar