Respond to collisions#4
Conversation
|
Hey that sounds like a great start! The Rigidbody class already handles forces to some extent, though I don't think it's yet handling off-axis forces (imparting torque). So that's something we will need. I do worry a bit about the performance of using SAT on every pair of rigidbodies. But I guess let's just get it working first, and we can optimize later. A vec2 module is a good idea, however, instead of using maps, I would prefer to use a 2-element list — and we can define accessors to allow us to reference elements as .x and .y instead of [0] and [1], like this: But the nice thing about this is, you don't really need a separate factory function to make these; you can just return Welcome to MiniScript, and thanks for your efforts! I look forward to working with you on this. |
If I understand it correctly then that list wouldn't have any methods of the vector type right?. We could then instead make regular functions in the vector module, but that seems a bit more unwieldy. Although it quite handy to be able to create them with just a list, hmm.. |
Not necessarily. We can add more list extension methods, as needed. For some examples (and to be aware of the list extensions the user will likely already have in effect), see: https://github.com/JoeStrout/minimicro-sysdisk/blob/master/sys/lib/listUtil.ms One thing we can't do in MiniScript is operator overloading. But notice that the above module (which you can use in your own Mini Micro code by doing |
|
That would work but then we would be polluting the list type with vector methods, for example the vector's |
|
Also take a look at https://github.com/JoeStrout/minimicro-sysdisk/blob/master/sys/lib/matrixUtil.ms, which provides code for 2D matrices. Not sure if we really need that for 2D physics, but it's available. |
Sorry, I was unclear. Let me try again: Use the standard listUtil method. Just import it at the top of any physics script. It's a standard system-supplied library, so always available. Now you don't need to add a "vector We can add the Feel free to join me on Discord if you want to chat more interactively! Link's on the MiniScript home page. |
|
Ohh sorry, okay. I'm stupid and just saw the first couple of methods, I didn't see that there were more. Yeah I can totally use those and add more as I see fit. |
|
Thanks for your hard work! It looks like all we need now is torques (so blocks will collide & rotate properly). |
First time writing MiniScript, sorry for any mistakes!
In the
collisions.msfile I've added a Separating Axis Theorem collision detection implementation, which allows you to find whether or not two objects are colliding as well as finding out how much they are overlapping by. To aid with this I've also implemented a simple Vector2 type to handle vector math more easily, it's contained in thevector.msfile. It's not super optimized yet, but I'm leaving that for later.The collision response itself isn't done yet, what's there now is only a naive algorithm that always moves just one object. I would like to add some kind of force system, perhaps even with friction and bounciness.
I would also like to add an example for circles, which is one of the SAT algorithm's edge cases.
Fixes #1