-
What do you want to achieve? Keep it simple and clear!
-
What is the issue? Include screenshots / videos if possible!
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Hello! I am Witch. I have 4+ years of coding experience on roblox, but I still haven’t figured out how to make a rather good NPC system.
-
I would like to see if anyone can help me achieve a working and a good NPC combat system.
-
The main issue here is that I can’t make a good NPC system. I normally do PvP combat and other Magic systems.
-
I had tried to make my own NPC system, but its pretty bad and kinda sad to look at. I have a blocking system, and a dash I would also like to implement with this system.
I would like to have other people use this if possible. So if you guys need any more details, ask me and Ill respond as fast as I can.
I would like to go for a World of Stands NPC system or Noobs vs. Dummies NPC System
Thanks so much! -Witch(@witch2352)
The main thing with this would be having the npc reconise whats going on in its surroundings and using rays to find places out of sight from attackers, as for using dodge or abilities this would be in response to its surroundings and predictions based off where the player is looking.
- For finding whats going on in an area I tend to use a invisible part and quickly toggle collision on and then off with touch events and then filter the parts
- The raycasting is where things get a little tricky as you would need to fire rays from all humanoids nearby as well as checking nearby parts to see if the npc can hide behind them, ideally i would fire rays to a position slightly behind said object to see if the npc can take cover there
- Timing ideally you would want the npc to try to time its attacks so you would want it to run on a cycle of run/dodge and attack like a player would, id reccomend using math.random for some of this to make it less predictable
The main thing really is having it reconise its surrounding and the raycasting, once you have that down the rest is all down to adding in features
Will try to do some of that. I didn’t think about raycasts. I do have trouble with them though. I can only make them go in a straight thin line. Any idea on how to make the raycast spread out more?
I am also looking this up as I go.
raycasts only go in a line, the good thing is tho, think of them as a cframe lookvector and they are easy enough
So, I should use see if the player is looking at the NPC using a CFrame.lookAt()?
noo, as a way of thinking about raycasts, raycasts fire from a position with direction, which is near enough a cframe, this means you can essentially make a cframe and then use that cframe to fire the ray properly
Ohhh, ok that makes more sense. Thanks lol
I’m getting on studio right now to test this btw
Ill edit this in a sec with what i use for raycasting, havent put raycast params into it but its pretty reliable otherwise
local RayModule = {}
function RayModule.FireToPosition(Origin,Pos)
if typeof(Origin) == "CFrame" then
Origin = Vector3.new(Origin.X,Origin.Y,Origin.Z)
end
if typeof(Pos) == "CFrame" then
Pos = Vector3.new(Pos.X,Pos.Y,Pos.Z)
end
local CF = CFrame.lookAt(Origin,Pos)
local Direction = CF.LookVector
local Distance = (Pos - Origin).Magnitude * Direction
-- Fire Ray
return RayModule.FireRay(Origin,Distance)
end
function RayModule.FireRay(Origin,Direction)
local Result = game.Workspace:Raycast(Origin,Direction)
-- RaycastResult.Instance The BasePart or Terrain cell that the ray intersected.
-- RaycastResult.Position The world space point at which the intersection occurred
-- RaycastResult.Material The Material at the intersection point
-- RaycastResult.Normal The normal vector of the intersected face.
-- RaycastResult.Distance
return Result
end
--local raycastParams = RaycastParams.new()
--raycastParams.FilterDescendantsInstances = {caster.Parent}
--raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
--local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
--return Result
return RayModule
So this gets the info on where the player is looking right?
Its a generallised raycasting module, so you can take 2 positions and the script will fire a ray between them. Saves all the messing arround
Oh! Ok This will help.
Thanks a lot. I will post here again if I have another question about this.