I will make a guess that what you want to do is possible both without using Defold physics and without the manifold function in daabbbcc if you would like to use circle collicion shapes.
When two square sized units overlap, we know the positions, sizes and radii of both of them. We can simply get the distance between their centres and if the distance is less than the sum of their radii move the unit along the vector between their centres to compensate this distance.
It seemed to me that circle collision shape of units is more preferable to square for more dense positioning. But if there is no need in it and square collisions are akay, it’s easier to use the manifold function in daabbcc of course, I suppose it’s written in C++ and already does its job optimally.
Sure you can. If you have a (relatively) small number of circle collisions, you’re good to go. I’d like to share my experience on this:
I was working on a prototype (just for fun) using daabbcc as a broad phase and radius-based separation. I did something similar to what you described (circle collision + separation), initially using Lua:
But in the end, I had to move all the logic to C/C++. There’s a huge (and I mean huge) performance difference between using Lua (even with LuaJIT) and C/C++. I couldn’t manage to handle 200 units at the same time in Lua(of course, this might be due to my own poor implementation ) CPU usage would hit 100%. But with C/C++, I was able to handle around 500 units with only 25–30% CPU usage. Even using Box2D for this might be a better option when working with Lua(since it handles all movement/collision calculations at C).
I’m still tinkering with implementing circular manifold generation in this library…
For me this is critical. I could do something like this manually in Lua, but this kind of many-to-many check in update() would destroy performance for me I am sure.
Yeah, this is also my concern. I’m still not sure if this fits in this library or not. Also, my entire structure is based on rectangles, so it requires a lot of refactoring and testing. But I guess I’ll do it eventually anyway
So in the performance comparison, did you end up with a combination of built-in physics + daabbcc to support circular shapes, or did you go with rectangles only, but all in one daabbcc system?
I use built-in physics for positioning (unit to unit, and also tilemap collision objects for unit-to-world).
For everything else I use DAABBCC (e.g. damage, target finding, etc).
I didn’t spend a great deal of time thinking about this. I use DAABBCC wherever I can for performance purposes. Wasn’t sure how to implement positioning using DAABBCC so I used the built-in physics. Performance seemed okay, so I moved on!
If only I had waited a small amount of time, I could have used your manifold detection or whatever it’s called! I ended up making a platformer with your library without it though and it was fun; definitely a learning experience.
I would share the code for how I did it, but most likely people should just do it the new way.
Okay, so I already shared this with selimanac privately, but here is a game that was made with daabbcc, before the manifold detection existed.
Fair warning: most people consider this game to be a rage game, so…
So the collision is handled using a combination of raycasts and overlap detection.
This is 733 lines of collision code so… while I’m not going to walk you through all of it, there’s some useful functions in there that you can just drop in and use, like drawing the aabbs for tilemap, normalizing the results from raycast and overlap so you can handle them all together.
Of course some stuff you will think, “why did he do it this way.” IDK, I did my best.
Since Defold 1.10.0 (what a great release!!) is out, I can share the source of this platformer example project.
Meanwhile, I also added Live Update to the game collection. Now at least music and sound effects are loaded after the game launches.
You should consider it a basic prototype, not something ready for production. It might contain issues, but those issues are not related to this library.
Notes:
This is not a beginner friendly project, nor is it an easy-to-use module or a plug-and-play platformer solution.
It has become difficult to set up VMs on ARM macOS, and I no longer have access to Windows or Linux. So, I haven’t been able to test the project on those platforms.
I’m using a custom version of Defos because the default one wouldn’t focus (activate) borderless fullscreen on macOS. You might want to use the default one.
I’ve been trying to make the repo work on my Intel macOS laptop, but something is not working (seems to be related with the camera and , maybe?). The input, music and sfx are working, but the screen is empty.
@selimanac also mention that could be related with the newer GLFW version. I tried forcing OpenGL in the appmanifest but nothing happened. With Vulkan it just crashes.
Ah, one more thing ; are you using a Retina device? I’m using the new window.get_display_scale(), but I couldn’t test its result since I don’t have a Retina screen. You can test it by setting data.window_scale = 1 manually.
Also print(window.get_display_scale()) could be useful
Thank you. So you have a Retina display. As far as I can see from your screenshot, the camera zoom looks OK.
I have no idea either. OpenGL was deprecated a long time ago, probably starting with macOS 10.14. Apple might not be updating the old Intel graphics drivers for OpenGL anymore. So it’s better to stick with Vulkan on macOS, since it actually translates to Metal. I don’t think this problem is only related to this project (though it might be, since I have a custom render.script and shaders). You should test it with your own projects.
Yeah, I know. I haven’t been able to work with Defold in the last few months -and the editor improved a lot in that time! But with so many changes, probably my projects will have some issues too. Anyway, at least now I now this is something that may help upgrading them.