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: Advanced sight AI

Previous Thread :: Next Thread 
robocu3 is not online. robocu3
Joined: 13 Mar 2009
Total Posts: 6485
30 Jun 2012 06:36 PM
So I made a script that when you walk infront of this zombie and he sees you, he goes after you.

function getAngle(part)
local v = part.Position - script.Parent.Zombie.Head.Position
local a1 = math.acos( v:Dot(script.Parent.Zombie.Head.CFrame.lookVector)/v.magnitude )
return a1, v
end

function getClosestPlayer()
local dist = 5000
local tors = nil
for _, v in pairs(game.Players:GetPlayers()) do
if v.Character and v.Character:FindFirstChild("Torso") and v.Character:FindFirstChild("Head") and v.Character:FindFirstChild("Humanoid") and v.Character.Humanoid.Health > 0 then
local angle, vec = getAngle(v.Character.Head)
if math.deg(angle) <= 30 then
if vec.magnitude < dist then
dist = vec.magnitude
tors = v.Character.Torso
end
end
end
end
return tors
end

while true do
wait(0.1)
local tors = getClosestPlayer()
if tors then
script.Parent.Zombie:MoveTo(tors.Position, tors)
end
end
---------------------------------------------------------------------
It doesn't work and I don't know why. Any help?
-=Robo=-
Report Abuse
CombatHe is not online. CombatHe
Joined: 26 May 2012
Total Posts: 23
30 Jun 2012 06:38 PM
because EVERYTHING IS WRONG WITH IT


now go fix mine
Report Abuse
Supremmacy is not online. Supremmacy
Joined: 17 Mar 2012
Total Posts: 4159
30 Jun 2012 06:57 PM
Jerk.
-----
I honestly don't know what's wrong with the script. D:
Report Abuse
robocu3 is not online. robocu3
Joined: 13 Mar 2009
Total Posts: 6485
30 Jun 2012 07:23 PM
Combat, get off this forum if you're not going to help. This is the second post
I've seen you do this on.
So no help, I'm assuming?
-=Robo=-
Report Abuse
swmaniac is not online. swmaniac
Joined: 28 Jun 2008
Total Posts: 15773
30 Jun 2012 08:51 PM
Presumably the output says nothing?
Report Abuse
robocu3 is not online. robocu3
Joined: 13 Mar 2009
Total Posts: 6485
01 Jul 2012 06:04 PM
Output doesn't say anything on my PC. o_o
-=Robo=-
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