Trying to make non-character model w/ humanoid jump

I am trying to create an animal by using a Humanoid in a model. This works for making the model walk around (simply using Humanoid:MoveTo(part.Position)) however it seems I can’t make it jump by setting Humanoid.Jump to true. (is this even how you make players jump?)

How can I make my models “jump” in order to get over obstacles?

Currently I’ve done this which just results with them ascending slowly into space, and I feel this may not be the best way to do it anyways.

-- jumping
coroutine.wrap(function()
	while wait(1) do
		if script.Parent:WaitForChild("HumanoidRootPart").Velocity.Magnitude < .1 then
			local vel = Instance.new("BodyThrust")
			vel.Force = Vector3.new(0,7000,0)
			vel.Parent = script.Parent.HumanoidRootPart
			wait(.2)
			vel:Destroy()
		end
	end
end)()

-- moving around
while wait() do
	repeat block = workspace.blocks:GetChildren()[math.random(1,#workspace.blocks:GetChildren())] until block.Name == "G"
	script.Parent.Humanoid:MoveTo(block.Position)
	wait(5)
end

The two ways I know of adding a jump mechanism without setting the Jump property is:

  • Using Humanoid:ChangeState(Enum.HumanoidStateType.Jumping), which will cause the humanoid to switch to a jumping state, although it will allow the humanoid to also jump in the air.

  • Setting the velocity of the humanoid root part’s Y value to the humanoid’s jump power directly, which should give the same behavior. It has the same problem as the first point though.

The first definitely looks more proper. You can see if you are able to jump by detecting the state with Humanoid:GetState(), and comparing to a state that allows jumping, like Running or RunningNoPhysics.

3 Likes

You can prevent this “air jumping” by checking if Humanoid.Jump is already true. Yeah ChangeState is the best way to do it.

1 Like

Going by the actual Enums for HumanoidStateType:

  • The value of Humanoid.Jump is set to true if the humanoids state is Enum.HumanoidStateType.Jumping, and the “state only lasts briefly”, running when the player has “just jumped”.

  • When a player has jumped from a height, their humanoid’s state will, at one point, turn to Enum.HumanoidStateType.FreeFall, meaning their state can’t both be that as well as Enum.HumanoidStateType.Jumping, therefore the Humanoid.Jump value should result in false, whereas the player is still in the air after having jumped, which would allow “air jumping” if you just checked for that value.

There are probably ways to get around it as much as possible by comparing their state to all the possible states related to it.

This is all just paraphrasing off of the wiki page, so if that page is inaccurate this post is probably inaccurate. If it is, make sure to tell me.

2 Likes