Is there any way to detect collisions in Two.js?
What type of collisions are you referring to? Hit detection between mouse and object? Overlapping between two or more paths? Physics or velocity based changes?
Overlapping between two groups or paths
Unfortunately this doesn't exist out of the box at the moment. There are a number of workarounds depending on the use case. It is something I'd like to add though!
The current closest pure Two.js way of achieving this is to do a check against the bounding box of shapes ( Two.Shape.getBoundingClientRect ). Unfortunately this won't give you very high accuracy if you were doing a physics simulation.
Another way might be if you're using the svg renderer you can run path._renderer.elem.checkIntersection( someOtherElem );
Thanks! I will take a look at the methods you described.
I'm actually gonna keep this open, because I do want to add this into Two.js in the future.
I believe the functionality in 270 will cover this functionality as well. Closing as a duplicate. Thanks for reporting!
Unfortunately this doesn't exist out of the box at the moment. There are a number of workarounds depending on the use case. It is something I'd like to add though!
The current closest pure Two.js way of achieving this is to do a check against the bounding box of shapes (
Two.Shape.getBoundingClientRect). Unfortunately this won't give you very high accuracy if you were doing a physics simulation.Another way might be if you're using the
svgrenderer you can runpath._renderer.elem.checkIntersection( someOtherElem );
I can't help but speak about this response.
More often than not, in github issues, maintainers don't even bother to read a question and just barf a generic response, let alone providing a solid workaround like this.
This here is one of the best attitudes I've ever seen here. You took it seriously, possibly took your time to think about it and even though nobody would blame you if you just said there was no such feature, you gave a solution.
Moreover you wanted this thread to be open because you wanted to work on this. I think this mindset will help you achieve a lot. Cheers
Most helpful comment
I can't help but speak about this response.
More often than not, in github issues, maintainers don't even bother to read a question and just barf a generic response, let alone providing a solid workaround like this.
This here is one of the best attitudes I've ever seen here. You took it seriously, possibly took your time to think about it and even though nobody would blame you if you just said there was no such feature, you gave a solution.
Moreover you wanted this thread to be open because you wanted to work on this. I think this mindset will help you achieve a lot. Cheers