+ 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!
5 odpowiedzi
+ 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!
+ 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.
+ 1
im sorry, im new. but how to add a libary? Amitabh Kotha and thank you nk! ill try to use a libary.
+ 1
thanks! ill try around with it!
0
You can try to use SAT.js library available on github.
Link to the library :
https://github.com/jriecken/sat-js