|
Page 1 of 1
|
[ 8 posts ] |
|
How do I test if an actor is visible from a point?
Author |
Message |
The Wicked Flea
Joined: Fri Jan 04, 2008 10:51 pm Posts: 23
|
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.
|
Wed Dec 09, 2009 12:01 am |
|
|
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
|
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.
|
Wed Dec 09, 2009 12:48 am |
|
|
The Wicked Flea
Joined: Fri Jan 04, 2008 10:51 pm Posts: 23
|
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.
|
Thu Dec 10, 2009 5:13 pm |
|
|
Kyred
Joined: Sun May 31, 2009 1:04 am Posts: 308
|
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. Change the last parameter in CastMORay to something between 1 and 7. The higher the number, the last accurate the check, but the less calculations performed.
|
Thu Dec 10, 2009 7:01 pm |
|
|
Darlos9D
Joined: Mon Jul 16, 2007 9:50 am Posts: 1512 Location: Tallahassee, FL
|
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.
|
Thu Dec 10, 2009 7:27 pm |
|
|
The Wicked Flea
Joined: Fri Jan 04, 2008 10:51 pm Posts: 23
|
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?
|
Thu Dec 10, 2009 7:45 pm |
|
|
Darlos9D
Joined: Mon Jul 16, 2007 9:50 am Posts: 1512 Location: Tallahassee, FL
|
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.
|
Thu Dec 10, 2009 7:48 pm |
|
|
The Wicked Flea
Joined: Fri Jan 04, 2008 10:51 pm Posts: 23
|
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.
|
Fri Dec 11, 2009 7:48 pm |
|
|
|
|
Page 1 of 1
|
[ 8 posts ] |
|
Who is online |
Users browsing this forum: No registered users |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|