replit / kaboom

💥 JavaScript game library
https://kaboomjs.com
MIT License
2.66k stars 227 forks source link

Resolve and solid are incompatible #8

Closed grassick closed 2 years ago

grassick commented 3 years ago

My 7-year-old has started his first game and a problem emerged:

He wants the tanks to bump into each other and not pass under each other. But adding solid() to each and calling resolve() on each causes both to instantly zoom upward off the screen. How do you make two objects that move around not overlap ever?

slmjkdbtl commented 3 years ago

Thanks for trying out kaboom and filing this issue!

Right now most cases is having a user controlled player game object and only calling resolve() on that one, but yeah from a user perspective it's intuitive that giving an object solid automatically makes it not passable by other solid objects without even calling resolve(). I'm thinking about changing the system so that it only and automatically resolves when you call move() (provided by pos() component), but I'll have to test that. I'll try and get back to you later!

slmjkdbtl commented 3 years ago

oh sorry, the problem to your case is actually resolve() is checking for itself, a quick fix is trivial, adding soon

slmjkdbtl commented 3 years ago

fixed in https://github.com/replit/kaboom/commit/b5c5a0b8fa84287d77ee54e2b86e3680f40ce046 you can test with https://kaboomjs.com/lib/dev/kaboom.js or download the file from master branch

grassick commented 3 years ago

Works great! Thanks!

I did notice that one tank is able to push the other one around, but not the other way around. I suspect the order of the resolves? Having solid implement it without resolve would fix it, no?

slmjkdbtl commented 3 years ago

Yeah it's caused by the object order, it could be fixed by only trigger resolve() when the object moves or transforms instead of every frame, I'll try to make this automatic in the next version as a new feature

grassick commented 3 years ago

FYI, In version 0.5.1, one tank can push the other tank right through solid objects (e.g. out of the game entirely through the outer boundary wall and through obstacles)!