two.js icon indicating copy to clipboard operation
two.js copied to clipboard

Collisions?

Open oliver-ni opened this issue 8 years ago • 9 comments

Is there any way to detect collisions in Two.js?

oliver-ni avatar Mar 24 '18 04:03 oliver-ni

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?

jonobr1 avatar Mar 24 '18 17:03 jonobr1

Overlapping between two groups or paths

oliver-ni avatar Mar 24 '18 20:03 oliver-ni

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 );

jonobr1 avatar Mar 25 '18 18:03 jonobr1

Thanks! I will take a look at the methods you described.

oliver-ni avatar Mar 25 '18 23:03 oliver-ni

I'm actually gonna keep this open, because I do want to add this into Two.js in the future.

jonobr1 avatar Mar 26 '18 15:03 jonobr1

I believe the functionality in 270 will cover this functionality as well. Closing as a duplicate. Thanks for reporting!

jonobr1 avatar May 17 '18 21:05 jonobr1

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 );

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

toramanlis avatar Jul 28 '20 18:07 toramanlis

Don't think this has been implemented yet?

JorensM avatar Nov 07 '23 12:11 JorensM

It has not, but you can follow the progress of the canonical issue here: https://github.com/jonobr1/two.js/issues/596

jonobr1 avatar Nov 07 '23 21:11 jonobr1