how to add object collision to a wall | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

how to add object collision to a wall

I made this game, but i cant make the object collision work.. https://code.sololearn.com/W3i7v2LuHhoB Could someone help me with it? thanks alot!

5th Jul 2019, 8:44 PM
mine
mine - avatar
5 Answers
+ 2
Normally you’d add a script tag at the end of your html body with the link or import it using webpack or parcel, but Sololearn is odd and so instead on here you have to load by using either the window.onload function in javascript, “use strict” at the top of your javascript, or put your script tag in the head html dom element. (I think those work at least) good luck!
14th Jul 2019, 7:24 AM
nk361
nk361 - avatar
+ 2
Essentially basic collision works by having a constant check in the game loop’s tick method to see if the two object’s hitboxes overlap, if they do, for a collision type reaction, you normally push the character in the opposite direction at the same speed that they move towards the wall. This is why in some older games you can trick the simple collision by putting your back to the wall and walking forward. The old game thinks you’re colliding, adds the opposite speed to yours allowing you to walk inside of the wall. Nowadays, use a game engine or library made just for it to avoid sketchy collisions.
13th Jul 2019, 4:10 AM
nk361
nk361 - avatar
+ 1
im sorry, im new. but how to add a libary? Amitabh Kotha and thank you nk! ill try to use a libary.
14th Jul 2019, 7:17 AM
mine
mine - avatar
+ 1
thanks! ill try around with it!
14th Jul 2019, 8:24 AM
mine
mine - avatar
0
You can try to use SAT.js library available on github. Link to the library : https://github.com/jriecken/sat-js
11th Jul 2019, 2:28 PM
Amitabh Kotha
Amitabh Kotha - avatar