Closest guy to a point
Hi.
I am at a stage where I need to find the closest character to a given point, and I am not sure how to do it.
I have a point which is a football, which is described by a x, y and z float. And each character in the game has a x y and z point which describes their position.
But how do I find out how far each character is from the ball's position? Can I convert the line described by the characters position and the ball's position into a float that I can then use for comparisons?
Thanks for all help.
Vector algebra...
length(V1-V2), where v1=player, v2 ball.
BTW, you can speed up calculation by not taking square root in length calc.
length(V1-V2), where v1=player, v2 ball.
BTW, you can speed up calculation by not taking square root in length calc.
______________________________Madman
ah, but Vector1 - Vector2 will give me another vector made up of 3 floating points. The distance vector, I suppose I would call it.
How do I then tell which character's distance vector is longer? Because the vector describing the line is made up of 3 floating points, it isn't straight forward when comparing them. (at least to me)
How do I then tell which character's distance vector is longer? Because the vector describing the line is made up of 3 floating points, it isn't straight forward when comparing them. (at least to me)
lenght(vector)=sqrt (x^2 + y^2 + z^2);
In this case, as you are not going to use that lenght for anything that compare them, you can choose not to compute the sqrt.
Also, the play zone is planar, isn't it? Then you don't need to use the Y coordinate, as long as it's going to be similar for each character.
Your "distance" function would look like dist:
distance=(ball.x - player.x) ^ 2 + (ball.z - player.z) ^ 2;
In this case, as you are not going to use that lenght for anything that compare them, you can choose not to compute the sqrt.
Also, the play zone is planar, isn't it? Then you don't need to use the Y coordinate, as long as it's going to be similar for each character.
Your "distance" function would look like dist:
distance=(ball.x - player.x) ^ 2 + (ball.z - player.z) ^ 2;
theNestruoSyntax error in 2410Ok
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement