Timeline for Most Efficient Way to Check Player Distance from a Line?
Current License: CC BY-SA 4.0
12 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
May 16, 2019 at 10:56 | comment | added | Pete Bloom | @trollingchar Do you mean pick a point on the line and compare it to the player's position? I'm trying to avoid doing that because it isn't as precise as ideal. (Though I do have a solution I can revert to that does exactly that.) I think the issue with Maifee Ui's formula is that it's the general formula for the whole line if it just keeps going (I'm trying to look at how far the player is from specific segments of those longer lines is probably the best way I can describe it... i.e. whether the player is following a particular route through a larger grid pattern.) | |
May 16, 2019 at 10:43 | vote | accept | Pete Bloom | ||
S May 16, 2019 at 10:40 | history | suggested | Maifee Ul Asad | CC BY-SA 4.0 |
removed ? from title
|
May 15, 2019 at 14:10 | comment | added | trollingchar | If you know that the line is straight vertical or horizontal, you can simply find difference between line's coordinate and the object's corresponding coordinate. Otherwise, you should use the formula that Maifee Ui Asad suggested. It can't be simplified further. | |
May 15, 2019 at 14:05 | comment | added | trollingchar | @MaifeeUlAsad for example, compare squares instead of distances, to avoid expensive square root calculations (if he wants to find minimum or maximum distance). | |
May 15, 2019 at 13:36 | answer | added | Maifee Ul Asad | timeline score: -1 | |
May 15, 2019 at 13:04 | comment | added | DMGregory♦ | "I think I might have some trouble implementing that in unity's system" How about trying it first, using the basic formula you can find with a Google search. It will probably work just fine for your needs — it's a very cheap calculation by game standards. If you encounter a problem, edit your question to detail exactly how you implemented it and what specific problem you found, then we can help you solve that problem. | |
May 15, 2019 at 10:30 | comment | added | Pete Bloom | I have several lines, each of which are made up of a number of game objects (because some need to be visible at different times). I need to find the closest line to the player at each time point throughout the game. | |
May 15, 2019 at 5:47 | comment | added | Maifee Ul Asad | There is a direct formula, what kind of optimization you are talking about ? | |
May 15, 2019 at 5:45 | comment | added | Maifee Ul Asad |
gameObject.transform.position it gives GameObjects 's location in 3D space, now calculate according to your formula
|
|
May 15, 2019 at 5:43 | review | Suggested edits | |||
S May 16, 2019 at 10:40 | |||||
May 15, 2019 at 3:01 | history | asked | Pete Bloom | CC BY-SA 4.0 |