How to prevent floating for anchored non-humanoid NPC's

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

Not have floating NPCs.

  1. What is the issue? Include screenshots / videos if possible!

Since NPC’s without Humanoid NEED to be anchored so that it doesn’t fall-over, it doesn’t have gravity so it cant really go down.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I tried making the NPC go a little bit down on Y axis when left leg isn’t touching anything, but that doesnt seem to fix the issue.

tempoverlapparams.FilterDescendantsInstances = {enemy.Parent}
			local LeftLeg : Part = enemy:FindFirstChild("Left Leg")
			
			if #workspace:GetPartBoundsInBox(LeftLeg.CFrame, LeftLeg.Size, tempoverlapparams) < 1 then
				enemy:PivotTo(enemy:GetPivot() * CFrame.new(0, -0.01, 0))
				print(#workspace:GetPartBoundsInBox(LeftLeg.CFrame, LeftLeg.Size, tempoverlapparams))
			end

Can’t you weld it together or use motor6ds?

What do you mean? How can I do it?

Have you heard of welds before? They basically attach parts together without having to anchor them, but I suggest using motor6ds which are basically the same but allow animations to be played on them.

How would this prevent NPC floating???

I already know about motor6d’s but how exactly will this be used to help

What about making the NPCs Humanoids? Then they would fall/make contact, you could also then have them jump or do all the other things a humanoid can do.

Add a Humanoid class to your NPC model, then in script.

local human = npc.Humanoid
human.Jump = true
human.WalkSpeed = 4
etc...

Because the parts won’t have to be anchored, so they retain physics.

Too laggy. Game needs to run about 30 active npcs at the same time.

Where would I weld the HRP? If I just unanchor the character then they would just fall over themselves.

I don’t recommend welding because obviously you want animations too, use a motor6d and make part0 the HRP. part1 is every other body part you want to attach to HRP aka part 0. Since HRP is usually the joint.

What about raycasting from the torso towards the floor every few frames to adjust your NPCs height? You can load balance your raycasts over multiple frames and use parallelisation to achieve very good performance that way. Setting up a smaller whitelist of specific parts you want your NPCs to stand on and keeping the raycast length somewhat low can decrease the computation time of raycasts further.

Im already doing that, thats literally the default.

Ill try this when I have the time.

Oh, then you could use alignposition/alignorientation to keep the parts together sort of. Without humanoids, but c’mon now humanoids aren’t that evil. You should just add them.

I had a cube that needed to bounce when a player came near it, I made 3 different scripts to generate the effect using postion, CFrames or tweens using while/for/heartbeat loops (thought about making another one using raycast but I didn’t go there). They all “work” but the easiest one by far was the fourth, which was to just add a humanoid to the cube, assign the rootpart and then say cube.Jump = true.

Also makes it super simple to change walkspeed, jumpheight, walkto, slope control, name plates, hip height, etc… it’s a really handy class even if the enemy is a just cube, a model or almost anything else you want to have walk, jump or otherwise behave like a player/NPC, which really seems like a fit for what you’re trying to do.

I just did this, I calculated the NPC’s height and then raycasted downwards, if no part is under the npc, then lower the npc.

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