|
Hey, Drawing: So, the first bracket is game object, it scans in front of it at some angle, and returns any gameobjects within that angle, (I'd like the nearest, but I can figure that out). I've been trying to think of how I can get this to work, and I know of methods such as SweepTest, which does roughly what I want, or a simple raycast, but I want it within an angle, not the "sphere" that does 360. I've thought of combining a raycast with a rotating object that'd rotate a certain degree amount and return an array of objects hit (If any) but I don't know how angles work to well, as in, I don't know how to have it literally rotate and while it rotates, it searches and returns (If you can help me with examples, I don't know Eular/Quartarians to well, and I've read the documentation, but their aren't any manually rotate an object that I could find). Finally, my last case I could do, but I don't want to, is spawn the item with 2 empty game objects at the angles I'd like to check, then it simply starts rotated to one, then rotates the other real fast and checks, but this seems a shoddy way of doing it... My current code that doesn't work (Maybe spark imagination in you? =P): It's a 2D thing though, so i don't need anything from other angles. Any help/links would be appreciated.
(comments are locked)
|
|
In your code, The angle is always positive (it won't tell you if 10 degrees is clock or counter-clockwise) so can just check A problem with the angle method is you miss things very close to you. Imagine a large cow one unit ahead at 45 degrees. A 25-degree angle test misses it, even though its rear legs are right in your face. Widening the angle for close objects seems to help. For a collider method, maybe you could make a big wedge-shaped mesh and use that as a meshCollider for a triggerBox (not sure meshColliders are allowed for that.) I actually considered doing the wedge-shaped mesh to do this, it just seemed like a very... Backwards?... way of doing it. I did change my code to: var angle = Vector3.Angle(gameObject.transform.position, (listOfObjects[i].gameObject.transform.position - gameObject.transform.position)); as an attempt to do what you said (I believe, target minus me) and it still doesn't work. My output angle has no pattern that I can find. Maybe I'm missing the solution, but do you have any besides the mesh? Thanks!.
Dec 08 '11 at 02:07 AM
Justin Warner
I just did the mesh, it doesn't work badly, still seems backwards haha. Thanks =P.
Dec 08 '11 at 03:27 AM
Justin Warner
First input to Angle is transform.FORWARD -- the direction you are facing. If you think about it, kind of hard to scan in front of you if you don't tell it where in front of you is. Thanks for letting me know the mesh works.
Dec 08 '11 at 01:25 PM
Owen Reynolds
What you say makes sense, but I can't seem to get it to work. I kinda like the mesh anyways, at least for now... I'll come back to this if I feel a need to find another way. Thanks for your time none-the-less. =)
Dec 08 '11 at 02:15 PM
Justin Warner
(comments are locked)
|
