detecting corners from co-ordinates

Hi Unity Community.

So at the moment I’m trying to determine whether there has been a corner drawn in a user input based on a change in direction of the co-ordinates.

The system I’m using at the moment is very makeshift:
I find the direction vector for each co-ordinate
add the direction vectors to a list
every time a co-ordinate is added find the average of the list
if the any of the values of the direction vector of a co-ordinate is in the opposite direction to the average mark this as a corner.

obviously this is very makeshift since It is prone to error (for example if the user has a bit of a wobble in their input or if they’re drawing non-diagonal lines (e.g. a square))

so basically I wanted to find a way to determine whether there has been a significant change in the direction. Any help would be greatly appreciated.

You might be able to use a dot product for this. Get the dot product between the previous coordinate and the current one, and compare it against a tolerance constant (something like 0.5) to see if it is a drastic change in direction:

if(Vector2.Dot(currentCoordinate, previousCoordinate) <= 0.5) {
    // this is a corner, do stuff...
}

See: Unity - Scripting API: Vector2.Dot