generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Making detection AI?

Previous Thread :: Next Thread 
doneyes is not online. doneyes
Joined: 21 Mar 2008
Total Posts: 3466
22 Nov 2013 03:37 PM
This is what I'm talking about: http://www.bitsalive.com/sight-and-hearing-for-our-aliens/

The only question I have is how can I get that field of view? I figure I'd use raycasts, but I don't know how this will work. Everything else is pretty simple though.
Report Abuse
breuning is not online. breuning
Joined: 30 Oct 2008
Total Posts: 4268
22 Nov 2013 03:40 PM
making an ai with raycasting is pain in the butt
believe me
Report Abuse
Jetta765214 is not online. Jetta765214
Joined: 22 Oct 2008
Total Posts: 1855
22 Nov 2013 03:59 PM
It's not that much of a pain. I added it to some AIs i made without trouble :/.
Report Abuse
Bebee2 is not online. Bebee2
Joined: 17 May 2009
Total Posts: 3985
22 Nov 2013 04:09 PM
Raycasting AI -

A. Get head position.

B. Get the lookvector of the head.

C. Multiply the position of the head by the lookVector by X amount. That will be how far it sees.

D. Create the ray.

E. FindPartOnRayWithIgnoreList

F. You do the rest.


This won't work for the peripheral vision, though.
Report Abuse
Jetta765214 is not online. Jetta765214
Joined: 22 Oct 2008
Total Posts: 1855
22 Nov 2013 04:25 PM
For side vision:

It is easy enough, I made this script open to the public, and can be found at:
http://web.roblox.com/RPG-Twilight-Knight-v0-4-place?id=2407374

That is a great place to look for scripts or ideas.

if (player[i].Character.Torso.Position-script.Parent.Torso.Position).magnitude <= eyesight then
print("Close Enough")
local direction = CFrame.new(script.Parent.Head.Position,player[i].Character.Head.Position).lookVector
local needlook = math.atan2(direction.x, direction.z)
needlook = math.deg(needlook)

local direction = script.Parent.Head.CFrame.lookVector
local islook = math.atan2(direction.x, direction.z)
islook = math.deg(islook)

if islook-needlook < sidevision and islook-needlook > -sidevision then
Report Abuse
Bebee2 is not online. Bebee2
Joined: 17 May 2009
Total Posts: 3985
22 Nov 2013 04:27 PM
Then you would raycast that. Not bad, not bad.
Report Abuse
doneyes is not online. doneyes
Joined: 21 Mar 2008
Total Posts: 3466
23 Nov 2013 12:05 PM
Jetta, that makes it so that it only activates if the ray is in the correct distance and it is in the 'artificial' 'FOV'?
Report Abuse
doneyes is not online. doneyes
Joined: 21 Mar 2008
Total Posts: 3466
23 Nov 2013 02:52 PM
I can't figure out what I need to classify sidevision as. Is the determining factor for the FOV?
Report Abuse
doneyes is not online. doneyes
Joined: 21 Mar 2008
Total Posts: 3466
23 Nov 2013 03:01 PM
Yep so I played around with it and it's the FOV. Thanks for the script, it's saving me a decent amount of trial and error.
Report Abuse
doneyes is not online. doneyes
Joined: 21 Mar 2008
Total Posts: 3466
24 Nov 2013 04:02 PM
Okay I'm going to return the favor now by giving you an improved version.


eyesight = script.DetectionDistance --these are int values childrened to the script. I have eyesight set to 35.
sidevision = script.FOV --this one is set to 45
target = game.Workspace.doneyes -- Change this so that it matches the actual target

while wait(1) do
if (target.Torso.Position-script.Parent.Torso.Position).magnitude <= eyesight.Value then
print("Target in range of detection.")
local direction = CFrame.new(script.Parent.Head.Position,target.Torso.Position).lookVector
local needlook = math.atan2(direction.x, direction.z)
needlook = math.deg(needlook)

local direction = script.Parent.Head.CFrame.lookVector
local islook = math.atan2(direction.x, direction.z)
islook = math.deg(islook)

if islook-needlook < sidevision.Value and islook-needlook > -sidevision.Value then
ray = Ray.new(script.Parent.Head.CFrame.p, (target.Torso.CFrame.p - script.Parent.Head.CFrame.p).unit*eyesight.Value)
hit, position = game.Workspace:FindPartOnRay(ray, script.Parent)
if hit then
if target:IsAncestorOf(hit) then
print("Target detected.")
else
print("Target is hidden")
end
end
end
end
end
Report Abuse
doneyes is not online. doneyes
Joined: 21 Mar 2008
Total Posts: 3466
24 Nov 2013 04:04 PM
to make that work, just put it in a script, put that script under the AI and the AI will look through its head to find you. Inside the script you need to put two int values. Instructions for those int values are in the first few lines of the script.

The primary difference is that the AI can't see the target through a wall now. It's also fixed to work as it is rather than a rough chunk of script.
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
24 Nov 2013 04:24 PM
Take my alien. If has a FoV thing in it.
Report Abuse
doneyes is not online. doneyes
Joined: 21 Mar 2008
Total Posts: 3466
24 Nov 2013 05:21 PM
This one does as well
Report Abuse
notsopwnedg is not online. notsopwnedg
Joined: 07 Nov 2010
Total Posts: 4182
24 Nov 2013 05:22 PM
Pft...But the one that AFF made must be better

:0
Report Abuse
doneyes is not online. doneyes
Joined: 21 Mar 2008
Total Posts: 3466
24 Nov 2013 06:01 PM
It probably even does my homework!
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image