Timeline for How would I check the range against the entirety of an enemy object, and not just it's transform.position?
Current License: CC BY-SA 3.0
22 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| May 4, 2015 at 9:01 | comment | added | Douglas Gaskell | Thanks Jon. I'll definitely use that optimized version, no need to run the Dot work twice. I want to clarify that I am using the correct method to identify a side. The Dot will tell me the side, however there are two Dot products per quadrant (+ & + = top-right sides, - & - = back-left sides)Just because there is a positive forward Dot does not mean it's on the front face on a rectangle, it could be on the left or right face. This is how I'm finding the side: i.imgur.com/vjLsO3Z.png. using the angle. Is that the proper way to do that? Those angles are arbitrary, not real to the shape. | |
| May 3, 2015 at 23:27 | comment | added | Jon | Also, since you'll already have the Dot calculated, you can just ACos() it, to retrieve the angle, in radians. (I suspect Angle() does this, internally, so avoid duplicating the Dot work) | |
| May 3, 2015 at 23:22 | comment | added | Jon |
@douglasg14b, thanks; I'll tweak it some more. Since Unit-Hypotenuse is always 1, the scaled hypotenuse length will always equal the scale-factor. The only optimization left is that Cos(angle) is equal to Dot. The fully-optimized formula is, therefore, HypotenuseLength = AdjacentLength / Dot (which was the "scale-factor" formula).
|
|
| May 3, 2015 at 23:13 | comment | added | Douglas Gaskell | I'd say readability may have went down with the cluttered text. However it's easier to determine which variable is which with the colors, as well as determine the flow from the numbers. Here is what I came up with when I drew this out to make sure I understood (in ms paint though): i.imgur.com/vUBf3RL.png Though it looks like I just kind of dropped the Scale Factor entirely for unities built in Vector3.Angle() method. | |
| May 3, 2015 at 23:02 | history | edited | Jon | CC BY-SA 3.0 |
additional diagram
|
| May 3, 2015 at 21:46 | comment | added | Jon | @douglasg14b, bingo! I use AutoCAD (Civil 3D) for work, and play. | |
| May 3, 2015 at 20:07 | comment | added | Douglas Gaskell | Scratch that Jon, I got it. Didn't even realize the trig there. Cos(angle) = adjacent leg/hypotenuse. I have the angle and the adjacent leg, I just need to solve for the hypotenuse. | |
| May 3, 2015 at 19:52 | comment | added | Douglas Gaskell | Thanks Jon. Don't mean to bug you more than I should, your answers are always amazing. However I'm a bit confused about the above diagram. I've gotten to this point: i.imgur.com/uMBX6wG.png and I'm not entirely sure how to proceed with finding the length of the 2nd side of the triangle so I can find the hypotenuse. Unrelated, what application do you use for your diagrams? They are quite nice. | |
| May 3, 2015 at 16:19 | history | edited | Jon | CC BY-SA 3.0 |
added 111 characters in body
|
| May 3, 2015 at 8:08 | comment | added | Jon | @douglasg14b, I've added a blow-up and additional details. | |
| May 3, 2015 at 8:07 | history | edited | Jon | CC BY-SA 3.0 |
added 351 characters in body
|
| May 3, 2015 at 7:58 | history | edited | Jon | CC BY-SA 3.0 |
added 351 characters in body
|
| May 3, 2015 at 6:42 | comment | added | Douglas Gaskell | Hey Jon, out of curiosity, would there be a way to get the distance for an object like the grey one in your image where there is no corner within range, yet part of the body is. Without a custom mesh with extra points (Like a hexagon stretched to fit the form of the ship). | |
| May 2, 2015 at 8:41 | comment | added | Douglas Gaskell | Just tested it with 100,000 calculations per frame(component caching was pretty important at these numbers). It chopped off 14.8ms of frame time, while 1,000 raycasts chopped off 135ms of frametime. I would have to perform 1,000,000 of these methods per frame to equal the performance cost of 1,000 raycasts. In other words, this is 3 orders of magnitude more efficient, bravo. | |
| May 2, 2015 at 8:21 | comment | added | Douglas Gaskell | I'm also pretty sure how to make the checks more granular. For instance checking a 6-pointed shape instead of a 4-pointed shape for more accurate results. Just requires more checks and dot products. | |
| May 2, 2015 at 8:13 | comment | added | Douglas Gaskell | Thanks, I just got some time together and implemented it. Here is a paste of my first method that works: pastebin.com/FpsNEqDT. It's a bit oversized for a method and will be broken down. However I'm a bit dubious about the performance difference between it and a raycast now, there is quite a bit going on in there. It would probably be great if I handed off the math to another thread for 100's of units, but I'm not that far. I will set up a scene for profiling and report back on my findings vs raycasts. | |
| May 1, 2015 at 2:43 | vote | accept | Douglas Gaskell | ||
| May 1, 2015 at 1:44 | history | edited | Jon | CC BY-SA 3.0 |
added 2 characters in body
|
| May 1, 2015 at 1:38 | history | edited | Jon | CC BY-SA 3.0 |
edited body
|
| May 1, 2015 at 1:33 | history | edited | Jon | CC BY-SA 3.0 |
edited body
|
| May 1, 2015 at 1:23 | history | edited | Jon | CC BY-SA 3.0 |
added 22 characters in body
|
| May 1, 2015 at 1:04 | history | answered | Jon | CC BY-SA 3.0 |