I am making a platformer, where my player is represented as a circle and the ground is represented as lines. The actual collision detection and resolving works, it's just an edge case I can't find a solution for.
I check on which line the hero is by using the normal, and if the hero's center is between these normals I know he is on that line. That works except for the case in the image above. When he get's in the 'Problematic Area' the algorithm will not detect any collision.
So how do I know which line to pick for the collision when the hero get's in this area?
Here is some code that shows how I test collisions (which again works, but does not consider the problem I actually have).
playerPointer:Vector2D = New Vector2D(position.x - line.x1, position.y - line.y1) lineNormal:Vector2D = line.vector.Copy() lineNormal.LeftHandNormal() playerOnNormal:Float = playerPointer.ProjectionOn(lineNormal) playerOnLine:Float = playerPointer.ProjectionOn(line.vector) #Do we have a collision between the circle and the infinite line If Abs(playerOnNormal) <= radius #Get the direction vector of the line Local directionVector:= New Vector2D(line.x2 - line.x1, line.y2 - line.y1) #Is the player inside the normals boundaries If (playerOnLine <= directionVector.Length) And (playerOnLine >= 0)