I want to make a similar ai that can actually see and detect people if it’s player or not.I’m currently making a The Mimic ai but I don’t want to raycast it infront since I’m new to ai making stuff.
there are multiple tutorials on youtube for this
Raycasting is really the only valid way to do this. It has a lot of benefits
- relatively easy to implement
- works with walls
- very customisable with properties like
RaycastParamsparamater to raycast methods.
I’m actually thinking that I can’t just raycast it infront like just straight the player’s head,I want it to be like left and right too but if the player jump out of the raycast then it would bypass the vision.I want it to see the player inside the raycasting
Raycasting is not performant and there are better ways like using dot product. Example:
local PlayerPosition = -- players position local HumanoidRootPartOfNPC = -- origin point that being the npcs position local ToPlayer = (PlayerPosition-HumanoidRootPartOfNPC.Position).Unit local LookVector = HumanoidRootPartOfNPC.CFrame.LookVector local DotProduct = math.deg(math.acos(LookVector:Dot(ToPlayer))) if DotProduct < 90 then print("In Vision") end
This has been answered multiple times in forum. For simplicity’s sake, I’ll link the one which would be most helpful.
This isn’t a valid way to do this because of walls. This does not factor into account that there are objects that could obscure the AI’s vision.
Also, this has seemingly infinite range too.
You could combine both the dot product method and raycasts as suggested above this method for a far more efficient method.
dunno where you heard that from, but roblox’s raycasting is actually very lightweight and safe to run in high-intensity scripts. you may be referring to the legacy raycasting,
Ray.new(), rather than the modern
Agreed, I was a little confused when I heard that so I did a bit more research and, yeah, you’re completely right.
add a cone shaped object in front of the npc that detects touched events is how i would go about this
instead of using touched events, you could use :GetPartsInPart() to get the parts in the cone-shaped area, but im confused as to why you cant just use :Dot()? its both more preformant and easier to manage.
No,what I want here is when you hide in some wall it can’t see you
Very useful!It did work fine and the result are really good since the ai is able to chase the player down now.Thank you for helping me!!
My aim is to give the OP a rough idea.
Hm, well okay but as I stated there is a better more accurate way of detecting player within a specified FOV. And using raycast can be sometimes hectic, in my opinion.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.