Align position and orientation bugging

i have a humanoid model constantly moving toward the player at an offset using align position and align orientation

randomly if i go too fast or hit something too fast or go through something too fast the model will just be sent out somehwere crazy and be destroyed

how do i prevent this

If you don’t need collision for your NPC humanoid model, considering setting its collision group so that it doesn’t react like that and fling into the sky.

If that’s not feasible, another thing you could do is, just check your alignPosition’s speed, like how responsive it is, don’t make give it too much force or anything like that, so it doesn’t collide with anything mid-way and fling. Try experimenting and testing with different properties of your AlignPosition

Another suggestion, and I think this might be the best one considering you situation, make it so that your NPC can’t collide with anything mid-way, change collision group for that, and then after the NPC’s destination is reached, make it back to Default again.

Also, maybe you can consider using pathFindingService’s methods too? I’m not sure how you’re thinking of your NPC to be like, is it like it is flying at an offset beside your player, then in that case pathfinding might not be really that feasible.

Hope these suggestions help!

Example (in a server script):

local PhysicsService = game:GetService("PhysicsService")
PhysicsService:RegisterCollisionGroup("NPC")
PhysicsService:CollisionGroupSetCollidable("NPC", "Default", false) -- Roblox always has the "Default" Collision Group, if you turn off collision with NPC and Default, then there's no way your NPC will fling because your NPC collides with absolutely nothing  (assuming you only have Default collision group)

local function makeItNotCollidable(npcCharacterModel)
     PhysicsService:SetCol
    for _, v in ipairs(npcCharacterModel:GetChildren()) do
        if v:IsA("BasePart") then
           v.CollisionGroup = "NPC"
        end
    end
end

local function setDefault(npcCharacterModel)
    for _, v in ipairs(npcCharacterModel:GetChildren()) do
        if v:IsA("BasePart") then
           v.CollisionGroup = "Default"
        end
    end
end

You can use this example and adapt this in your codebase. Like use the first function (to make it not collidable), and then use the second first to make it collidable. In the function’s parameters, you have to send your NPC Character which is actually a “model” as well.

Edit:

If you don’t need your NPC to be collidable at any point, then you can make your AlignPosition’s force higher and make it forcefully complete aligning its position, but also set its collisionGroup to the “NPC” forever.

2 Likes

yeah, this ended up working
thanks

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.