How do I do line rectangle collision? It seems way more complex than usual, here's the code. I'm trying to make r1 collide with the blue lines on r2. The collision method is vertextIntersect() in the Rect object.
I am not asking for rect collision, I am asking for line rect collision. The code draws blue lines over the second rectangle, I want to collide with 1 line.
Clueless Coder Quite close
Center of moving square, correct.
For blue line, make it not a vertical line, make it with a random angle.
Find the nearest point on the line which has shortest distance from center of square.
Calculate the distance between that point and the center of square.
For solving rect1 being stuck to rect2 currently, here is my demo for another Sololearner a year ago :
Use a flag to indicate that the shaped are overlapping, so that the direction will not be switching every frame.