How to fix taller zombies sinking inside the path in Tower Defense Game

So I’m encountering this problem where bigger zombies in my TD game are sinking inside the path, whereas on the other hand, smaller zombies walk on the path perfectly fine.

How can I make the script adjust the Y-axis so the bigger zombie will walk on the path perfectly?

Code:

function zomb.Move(Zombie)
	local speed = Zombie.cfg.Speed.Value * 100
	local pathway = workspace.pathway
	local BezierPath = require(workspace.BezierPath)
	local waypoints = {pathway.Spawn.Position}

	for i = 1, #pathway:GetChildren() - 2 do
		table.insert(waypoints, pathway[i].Position)
	end

	table.insert(waypoints, pathway.Exit.Position)

	local NewPath = BezierPath.new(waypoints,4)
	local HumanoidRootPart = Zombie.HumanoidRootPart

	for t = 0,1,1/speed do
		HumanoidRootPart.CFrame = NewPath:CalculateUniformCFrame(t)
		task.wait(0.01)
	end
	Zombie:Destroy()
end

Here’s the problem in a video:
robloxapp-20240711-2231209.wmv (1.4 MB)
How it’s supposed to work:
robloxapp-20240711-2231498.wmv (981.5 KB)

Here is the module: BezierPath, an easy to use and optimized spline path module for TD games and general paths - Resources / Community Resources - Developer Forum | Roblox

1 Like

I believe you could change the hipheight of the humanoid inside the taller zombie.

humanoid.HipHeight = 0 -- Default is 0

That won’t work since I don’t use :MoveTo function, I use BezierPath module to move my characters

Do you have access to positions from the module? Does the module only calculate it’s path with x and z positions?
I have no idea on how the module works
Would this work?

	for t = 0,1,1/speed do
		HumanoidRootPart.CFrame = NewPath:CalculateUniformCFrame(t) + Vector3.new(0, 1, 0)
		task.wait(0.01)
	end

This would work, but now, smaller zombies will float above the path. Is there anyway I can detect if the zombie is sinking and how much it is sinking to make them walk on the path normally

Try using the Pivot toolsto edit the center of the large zombies to be at the same height as the Pivot of the smaller ones.

Can you get rid of the Y axis value in the module and only calculate the X and Z axes?

Pivot tool method didn’t work for me :smiling_face_with_tear:
I don’t think I can get rid of Y-axis value in the module.

‘Y’ not? lol.
I don’t mean remove it entirely.
The Humanoid.HipHeight should take care of the Y axis. If so you could even make paths with hills and valleys.
If not just make the Y value in the script the Y Position of the Humanoid so it stays at the correct height.

HumanoidRootPart.CFrame = NewPath:CalculateUniformCFrame(t) + Vector3.new(0,Zombie.HumanoidRootPart.Position.Y,0)

Did you mean this when you said to set Y value in the script to the Y position of the humanoid?

Give it a try to see if it works.

Couldn’t you just change the hip height in the zombies humanoids without a script? I had this problem with scaled rigs and I set the humanoid hip heights higher in the rig until the rig did not go under the baseplate.

That didn’t work, now the zombies go infinitely up.

That wouldn’t work, because I’m using CFrame to move my zombies across the path.

1 Like

I’ve also tried using CFrame.FromMatrix() function but that didn’t really work out well.

for t = 0,1,1/speed do
	HumanoidRootPart.CFrame = NewPath:CalculateUniformCFrame(t) * CFrame.new(0, HumanoidRootPart.Size.Y * 1.5, 0)
	task.wait(0.01)
end
1 Like

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