I’m currently developing a game with guns. I’d like to implement a mechanic where NPC’s can block incoming attacks, similar to how NPCs in GPO (Grand Piece Online) block when skills are used skills, but i have no idea on how to do so.
I never played GPO, but I would go about seeing where your raycast has landed, if it is an NPC then why not trigger the block? It should be RaycastResult i think it has an Instance data type in it too… Not familiar with raycasts but i would say go for something like that. If you can explaion more to a noob like me please go for it haha RaycastResult | Documentation - Roblox Creator Hub
ok yeah makes sense, i could make a randomizer taht triggers the block when npc is hitted, thx for the idea. About the GPO system I can explain it, but not in a detailed way because I myself don’t know how it works precisely. Basically, there are skills you can use and sometimes when they are used, the npcs around you block before being hit or while you charge the skill, and continue to parry for a certain amount of time or until you use the skill. This is about how it works.
Once again i’m not 100% sure how it works, but you gave me a good start point thx.
Well, when a player starts the attack the way i would do it is make a bigger hitbox, and call it like NPCBlockChance or something, and this way you can use GetPartBoundsInBox. Then you can set a random chance of lets say 40/60 and check if it lands on the 40 side then make the npc Parry.
Or you can use GetTouchingParts i dont know the difference between them but maybe you can figure something out
When the client shoots and activates the raycast and it hits the smart NPC, you could either have a weightage system of blocking or blocking only if it’s a certain part (eg. head, torso). Personally I’d go for the first one since it’s better. You could even have an animation to go along with it, like make the NPC cross its arms to block the shot. The script below doesn’t fire a projectile but if you’re gonna fire one then simply make an invisible part in front of the NPC while playing the animation and destroy them both when the projectile hits the part
local ray = workspace:Raycast(gun.Position,npc.Position)
if ray and ray.Instance:IsDescandantOf(npc) then
local rannum = Random.new():NextInteger(0,100)
if rannum < 50 then
blockinganimation:Play()
else
npc.Humanoid:TakeDamage(50)
end
end
I haven’t touched this idea yet, but yeah i was thinking of something similar, when the ray hits the npc i can check if it’s part of a folder (since all my enemy npcs gonna be in a folder) and if yes i will start a randomizer that has a chance of blocking. I already have an attribute to see if a player/npc is blocking so i will just edit that value and run all the logic behind since it has some. Anyway thx for the reply .