Bug when detecting HumanoidRootPart Y Position

Hello, I made a script of a tool where when u use it, a bodymover push your character up, then when you’re falling, there spawn a part welded to the HumanoidRP in the feet height with a Touch Event so it detects it landed.

local HitBox = Instance.new("Part",HumanoRP)
        HitBox.CanCollide = false
        HitBox.Massless = true
        HitBox.CFrame = HumanoRP.CFrame + Vector3.new(0,-2.4,0)
        HitBox.BrickColor = BrickColor.new("Really red")
        HitBox.Transparency = 0.5

        local Weld = Instance.new("WeldConstraint",HumanoRP)
        Weld.Part0 = HumanoRP
        Weld.Part1 = HitBox


        HitBox.Touched:Connect(function(Hit)
            if Hit.Parent ~= Character and not Hit.Parent:FindFirstChild("Humanoid") then
                HitBox:Destroy()
                Weld:Destroy()
                print(HumanoRP.Position.Y)
                
            end
        end)
    end)

For some reason, everytime it detects I landed, the HumanoidRP Y Pos. has some kind of delay, after 1/4 of second it gets accurate but not the exact moment the part detects the floor.
I made some checks, and the difference was like above 15 studs from my actual HumanoidRP Y Position. And I was testing it on the same floor.
Output with the prints after using the tool several times
image
While the HumanoidRP Y Position should be something like this.
image

Is there a way to fix this? It gives me very bad problems because the things I want to make ends looking bad.

1 Like

This is a clever solution! Unfortunately physics is a little unreliable for things like this.

What you can do instead is listen for the HumanoidStateType.Landed state:

local conn
conn = Humanoid.StateChanged:Connect(function(old, new)
  if new == Enum.HumanoidStateType.Landed then
    print("Landed!")
    -- disconnect so we don’t fire twice
    conn:Disconnect()
  end
end)

Well, despite it may be an alternative for detecting if the Humanoid touched the floor, it doesn’t solve my problem of detecting the correct HumanoidRP Y Pos.
I’ve tested it on another place, where the HumanoidRP Y Pos is like 3 studs:
image

This is the script I’ve used instead, using the HumanoidStates.

	local HumanoidStateCheck 
	HumanoidStateCheck = Humanoid.StateChanged:Connect(function(oldstate,newstate)
		if oldstate == Enum.HumanoidStateType.Running or Enum.HumanoidStateType.Freefall or Enum.HumanoidStateType.RunningNoPhysics then
			if newstate == Enum.HumanoidStateType.Landed then
				print("------------------------------")
				print("The Character Landed State was detected!")
				print(" The HumanoidRP Y Pos is: "..HumanoRP.Position.Y)
				print("------------------------------")
				print("Rechecking HumanoidRP Position")
				print("------------------------------")
				
				task.delay(1/3,function()
					print("The actual HumanoidRP Y Pos is: "..HumanoRP.Position.Y)
				end)
				HumanoidStateCheck:Disconnect()
			end
		end
	end)

And these are the Output results after using it 2 times, I already checked it several times and is almost the same result, random Y Position the exact moment it detects the Character touched the floor, but after a little time the recheck was correct.
image

And I don’t like the HumanoidStates at all, because sometimes it doesn’t detect the landed State, I think this is mostly because I use bodymovers for impulsing my Character, I guess should make a table containing the possible states it may detect after falling and reaching the floor. Anyway, my problem is not how I make the Character impulse or how to detect it landed, the problem is once I detect it landed the precise moment I get the HumanoidRP Y Position it is not accurate.

Why would you want to do something like this?

If you want to spawn some kind of effects on the ground then raycasting would be the way to go.

I also highly recommend you use Statetypes as that is what they are there for. Making a custom state controller is hard. I speak from experience.

My idea was making a sort of Jumping Attack Skill, where the Character jumps high then stomps the ground, and effects and stuff shows up

Well, I guess my only solution for this would be making a raycast of like 40 studs from the HumanoidRP to bottom if I want the vfx spawn on the floor the exact time it detects the Humanoid landed, isn’t it?

Raycast are useful when you want to get accurate position and stuff. I think for your us case yes raycast are the best option.

Or you could make the effects bigger and hope that they look OK :flushed:

1 Like