Right now it’s not a problem I have but I need to be helped.
I’m trying to make an NPC, this NPC will have the ability to cross an obstacle in front of it (a wall) like SCP-106 (if you see what I’m talking about)
How could I implement this? because that’s the kind of thing I’ve never done before.
(quick question : Is there something in lua that check if a humanoid is in a part or not?)
Short answer:
You have to play some tricks with CollisionGroups using PhysicsService.
How to check:
Humanoids are parented to models, not parts… but if you mean if a player is in a wall, you could tell it by checking a zone smaller than and within HumanoidRootPart. If the check finds a part that is not part of the character or a part that is not CanCollide, then do something.
Alternative answer:
I remember there was some kind of exploit where it allowed you to walk through walls. I don’t exactly recall how it worked. It was probably deleting the walls local-side.
I don’t think others would know. You should provide a more generalised example rather than a specific one that’s known to a fairly small community.
In terms of walking through things, you’re most likely going to want to have a look at PhysicsService.
Realistically you don’t want to overdo your groups so you should only have a set number of things that can be passed through, such as doors. I probably wouldn’t allow wall or floor passage for the sake of Humanoid movements, collision detection and other nuances that you need to account for. If I had to name at least one, it’s that you have to account for the outside of a map and make sure players don’t fall into a void after passing through a wall.
When working with collision groups, be sure to only set the group of parts that are collidable. The feature doesn’t work with CanCollide false parts, because obviously that means they just won’t collide with anything. A regular character only has its HumanoidRootPart and Head as CanCollide assuming no external interferences are taking effect. You can also implement a form of check yourself.
local function setDescendantCollisionGroup(Descendant)
if Descendant:IsA("BasePart") and Descendant.CanCollide then
-- set collision group
end
end
model.DescendantAdded:Connect(setDescendantCollisionGroup)
for _, descendant in pairs(model:GetDescendants()) do
setDescendantCollisionGroup(descendant)
end
The above code will set existing BasePart descendants that are collidable to have a certain collision group, as well as any other parts that get added to the model. Figuring out the rest (resetting collision groups for parts moved out of the character hierarchy or filling in the function) is up to you.
Yes. Humanoids are descendants of models though, not parts. Models are assemblies and thus characters are assemblies. It’s as simple as using any of the find methods (WaitForChild, FindFirstChild, etc) on the model.
What exactly do you mean by specifications? You’ll have to be a bit more detailed in what you seek for me to be able to adequately answer your question.
Sorry for the inaccuracy. I mean, what is a “CollisionsGroup”?
*Excuse me if it’s still a little unclear as a question, but I don’t know how * formulate this question ^^
Documentation is available on the page I posted for the PhysicsService. Collision groups are meant to facilitate collision between parts in a group and another group.
In a nutshell:
A CollisionGroup is like a group of instances(especially parts, unions(those which has CanCollide properties)) assigned to a group, where they share same collision properties. Using these groups allows different interactions between CollisionGroup(s).
Okay: D, I’m going to experiment with this tomorrow.
but I’m asking myself a question.
I can make sure that ALL the parts, regardless of the name of the part, can be crossed by the humanoid (except the ground of course ^^)
can I do that?
for i,v in pairs(workspace:GetDescendants()) do
if not v.Name == "groundfloor" and v:IsA("BasePart") then
-- set the collision group here for v
end
end
Recommended to parent parts into models for which to ignore and which to be set.
It is indeed possible to allow Humanoids to pass through everything except floors, but again, I wouldn’t recommend it unless you’re prepared to take on the aftermath as well. Setting the collision group of walls means you have to make sure every single wall in your game, without fail, has a group set, which can start to become tedious. You then need to build a frame outside, connecting the entire map, so that players don’t just fall into the void and die.
I would go with my aforementioned suggestion of only allowing passage through certain items, such as doors. You can keep players in bounds with your map and there’s not as much to account for. Remember that walls are most likely not going to be the only thing you want players to pass through, so that means more collision groups and thus more accommodations - especially if you’re going to need collision groups between other objects.
I would recommend using my code over the one @anon81993163 posted as well, since it covers for both parts that get added to the character and ones that already exist. You should always try and account for new objects that get added to the hierarchy. Please check my response for that code.
as I currently don’t have time to configure CollisionsGroup for each object on the map, I will decide to change the way the NPC works
for that, I’m going to create a new post so as not to mix two topics but I’m going to keep this one because I’m going to keep working on it, I have to try some stuff
You can use NoCollisionConstraint, it works same as WeldConstaint or any other type of Constraint, I’m working on SCP-106 too and it was big brain time when I figured out this exists.