How to stop my monster from falling over

Hello, I was wondering how I prevent my AI monster from falling over. For example, it might trip over something and walk inside of the ground before flinging back up or when it jumpscares the player it might fall over and ruin the jumpscare.

This really breaks immersion and makes the game low quality. How do I prevent my monster from falling over? like how could I just compeltely remove the physics or something?

2 Likes

What is the script that moves the AI monster?

1 Like

this is the function which chases the player.

function chase(plr)
	if debounceEverything == false then
		local plrChar = plr.Character
		local plrRoot = plrChar.HumanoidRootPart
		if not jumpScaring then
			hum.WalkSpeed = 16
			run:Play()
		end
		chasing = true
		idling = false
		investigating = false
		task.spawn(gotAway, plr)
		local PathfindingService = game:GetService("PathfindingService")

		local path = PathfindingService:CreatePath(CustomPathfindingParameters)
		local pathconnection = nil

		while chasing and debounceEverything == false do
			pickState()
			if checkIfSee(plr) == false then
				ShouldContinue = true
				path:ComputeAsync(HRP.Position,plrRoot.position)

				if path.Status == Enum.PathStatus.Success then				
					local waypoints = path:GetWaypoints()

					for _, waypoint:PathWaypoint in waypoints do
						local distanceFromLastWaypoint = (waypoints[#waypoints].Position - plrRoot.Position).Magnitude

						if distanceFromLastWaypoint < 30 then
							hum:MoveTo(waypoint.Position)
							hum.MoveToFinished:Wait()
						else
							print("Broken")
							hum:MoveTo(HRP.Position)
							break
						end
						pathconnection = path.Blocked:Connect(function()
							ShouldContinue = false
							print("Path obstructed")
							return
						end)
						if ShouldContinue == false then
							print("Broken due to obstruction")
							break
						end
					end
					pcall(function()
						pathconnection:Disconnect()
						pathconnection = nil
					end)	
				elseif path.Status == Enum.PathStatus.NoPath then
					chasing = false
					investigating = false
					walk:Stop()
					run:Stop()
					task.wait(4)
					idle()
				end
			else -- We can see the player, why pathfind when we can run straight at them
				hum:MoveTo(plrRoot.Position)
			end
			RunService.Stepped:Wait() -- Wait to prevent Script timeout
		end
		run:Stop()

		idle()
	end
end
1 Like

To prevent your AI monster from falling over, you can use the Humanoid.AutoRotate property. By default, this property is set to true , which means the humanoid will automatically stand upright. If you set this property to false , the humanoid will no longer try to stay upright, and as a result, won’t be affected by gravity, effectively not falling over.

hum.AutoRotate = false

However, you might not want your monster to completely ignore physics because that could lead to unrealistic movements. You might want to use some physical properties to help stabilize your monster, for example, you can add a BodyGyro object to your humanoid’s root part to help it stay upright.

local bodyGyro = Instance.new("BodyGyro")
bodyGyro.MaxTorque = Vector3.new(0, math.huge, 0) -- this ensures your monster only rotates around the Y-axis
bodyGyro.CFrame = CFrame.new(monster.HumanoidRootPart.Position)
bodyGyro.Parent = monster.HumanoidRootPart

You also have to make sure your monster does not collide with small objects that might make it trip. You can do this by setting its Humanoid.StepHeight to a sufficiently high value.

hum.StepHeight = 5

This will allow your monster to step over any object that is 5 or fewer studs tall, preventing it from tripping over small obstacles. Adjust this value as needed for your game.

You should also adjust and add some things but since I do not know the details and the game and cannot help you further. hope It helps :slight_smile:

3 Likes

the body gyro works I think however setting auto rotate to false makes it so it doesnt turn in the direction its walking toward through moveTo() not disabling its physics.

2 Likes

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