07.11.2018, 21:36
I’m not that good at maths too, but i think you need to find ratio between vX - playerX and vY - playerY(ratio between distance to a car X, Y coordinates). Why you need to find this ratio? Because from this you can get an angle between a player and a car. Try drawing a triangle which longest line goes from player to a car(draw them as points), two shorter triangle’s lines will be just that longest’s line x, y projection. What you are trying to find is an angle which points to a car. Now try changing those x and y projections, notice how that angle changes, you should notice that there’s some pattern here. You should notice that if you make this triangle 2x times smaller, that degree doesn’t change. So that’s why we need to use ratio between x and y somehow. Basically, that’s where tan comes from. Tangent IS a ratio between those projections(and you can get this ratio from degrees, that’s tan function for you). But atan is reverse, it’s a degree which you are searching for, you input that ratio and it outputs some degrees to you. That’s how you get degrees between player and a car. Now you have to make sure that if player faces a vehicle, your degree needs to match player facing angle, if it does, you need to decide how much that angle can differ from an angle between player and vehicle(if it differs only 1 degree, you still can say that player is facing a car)... sorry for bad english and explanation, i hope this will help at least a little xd