Data Realms Fan Forums http://45.55.195.193/ |
|
How do I test if an actor is visible from a point? http://45.55.195.193/viewtopic.php?f=73&t=17333 |
Page 1 of 1 |
Author: | The Wicked Flea [ Wed Dec 09, 2009 12:01 am ] |
Post subject: | How do I test if an actor is visible from a point? |
I'm looking to make a scripted turret of sorts, and was wondering how I can find out if an actor is visible from a given point. I don't want this thing shooting at every actor on the screen when it has no hope of hitting it. I suspect that "SceneManager:CastSeeRay" or "SceneManager:CastObstacleRay", but which is it and how do I use it? I've not seen any use of either function yet. |
Author: | CaveCricket48 [ Wed Dec 09, 2009 12:48 am ] |
Post subject: | Re: How do I test if an actor is visible from a point? |
First, have a maximum distance for your area check. Next, cast a MORay in the direction of the actors in the area check (make sure you set the MORay to end itself when it hits groud). If the MORay gets an object with the RootID bieng the actor's, then let the turret fire away. If an actor is in the area check but is behind terrain, the ray shouldn't hit the actor if you set it correctly. |
Author: | The Wicked Flea [ Thu Dec 10, 2009 5:13 pm ] |
Post subject: | Re: How do I test if an actor is visible from a point? |
Thanks CaveCricket. Have you noticed if CastMORay is laggy when used a lot? It seems to have slowed my script. |
Author: | Kyred [ Thu Dec 10, 2009 7:01 pm ] |
Post subject: | Re: How do I test if an actor is visible from a point? |
The Wicked Flea wrote: Thanks CaveCricket. Have you noticed if CastMORay is laggy when used a lot? It seems to have slowed my script. |
Author: | Darlos9D [ Thu Dec 10, 2009 7:27 pm ] |
Post subject: | Re: How do I test if an actor is visible from a point? |
There's a problem with this though, one I haven't yet figured out how to solve: this method is great if the target is fully exposed, but if the center of their body is hidden behind something, the turret can't see the enemy even if everything else on them is exposed. The reason is that the ray is only going between the turret and the target's center. I guess we just need to look forward to next build allowing full AI control. I'm sure that'll make it easier. |
Author: | The Wicked Flea [ Thu Dec 10, 2009 7:45 pm ] |
Post subject: | Re: How do I test if an actor is visible from a point? |
Thanks Kyred, I fiddled with that, but it still wasn't efficient enough (the turret shot too slowly). I've kind of figured out how to solve your problem, Darlos. The problem with my solution is that it doesn't return an MO, just if it is adequately obstructed. Code: if SceneMan:CastStrengthSumRay(self.Pos, actor.Pos, 4, 128) < 80 then So then, if there's a little dirt (grass is ignored) in the way of the center-point the code is still called, but if it's more substantial it's ignored. It's one caveat is that it doesn't detect friendlies. So while this can rescue your "when to fire" problem, it causes the "should it fire" all over again. Perhaps "actor.EyePos" would solve the issue? |
Author: | Darlos9D [ Thu Dec 10, 2009 7:48 pm ] |
Post subject: | Re: How do I test if an actor is visible from a point? |
Well, you could do a MORay first, then follow it up with a StrengthRay. |
Author: | The Wicked Flea [ Fri Dec 11, 2009 7:48 pm ] |
Post subject: | Re: How do I test if an actor is visible from a point? |
Okay, I did the strength-ray to start and followed it up with an MOray, but there's one problem: actors with shields aren't fired upon. The obvious reason is because the shield is scanned. So what I did compiled a table of MOIDs associated with the given actor; check the table and for-loop in the following code. Code: if actor.Team ~= self.Team and vector.Magnitude < 375 then local actorMOIDs = {} -- the following is a table of MOIDs that are safe to shoot at. actorMOIDs[actor.RootID] = true -- shoot at our desired target for thingamajig in actor.Inventory do actorMOIDs[thingamajig.RootID] = true -- and anything it is carrying end local foundMOID = SceneMan:CastMORay(self.Pos, vector, self.RootID, 128, false, 5) -- strength was determined via logging to console, tweak in _10_'s... if SceneMan:CastStrengthSumRay(self.Pos, actor.Pos, 4, 128) < 60 and (foundMOID == nil or actorMOIDs[foundMOID] == true) then table.insert(targets, 1, actor) end end This way, my turret only fires on hostiles in range that have little separation in the way. |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |