Title. I’m experimenting with roblox’s new character physics controllers, and I’m using their default statemachine script. However, the jump they provide only activates on spawn and on slopes.
Stuff I tried:
Shapecasting under the player instead of using Roblox’s isControllerActive function
Printing every time I press space. For some reason, this works if you just take out all of the jumping logic but using the actual jumping code it only prints on a jump
Using a normal Vector3 instead of the JumpImpulse attribute. No dice
local function groundCheck()
local params = RaycastParams.new()
params.FilterDescendantsInstances = {character}
params.FilterType = Enum.RaycastFilterType.Exclude
local groundResult = workspace:Shapecast(ControllerManager.RootPart, Vector3.new(0, -5, 0), params)
if groundResult then
return groundResult
end
end
-- Manage attribute for configuring Jump power
ControllerManager:SetAttribute("JumpImpulse", Vector3.new(0,750,0))
-- Jump input
local function doJump(actionName, inputState, inputObject)
print("Jump")
local groundResult = groundCheck()
if actionName == "Jump" and inputState == Enum.UserInputState.Begin and isControllerActive(ControllerManager.GroundController) and groundResult.Material ~= Enum.Material.Air then
local jumpImpulse = ControllerManager:GetAttribute("JumpImpulse")
ControllerManager.RootPart:ApplyImpulse(jumpImpulse)
character.Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
ControllerManager.ActiveController = ControllerManager.AirController
-- floor receives equal and opposite force
local floor = ControllerManager.GroundSensor.SensedPart
if floor then
floor:ApplyImpulseAtPosition(-jumpImpulse, ControllerManager.GroundSensor.HitFrame.Position)
end
end
end
ContextActionService:BindAction("Jump", doJump, true, Enum.KeyCode.Space)
local ContextActionService = game:GetService("ContextActionService")
local ControllerManager = script.Parent:WaitForChild("ControllerManager")
local character = script.Parent
local function groundCheck()
local params = RaycastParams.new()
params.FilterDescendantsInstances = {character}
params.FilterType = Enum.RaycastFilterType.Exclude
local rayOrigin = ControllerManager.RootPart.Position
local rayDirection = Vector3.new(0, -5, 0)
local rayResult = workspace:Raycast(rayOrigin, rayDirection, params)
if rayResult then
return rayResult
end
end
-- Manage attribute for configuring Jump power
ControllerManager:SetAttribute("JumpImpulse", Vector3.new(0, 750, 0))
-- Jump input
local function doJump(actionName, inputState, inputObject)
print("Jump function called")
local groundResult = groundCheck()
if actionName == "Jump" and inputState == Enum.UserInputState.Begin then
print("Jump input detected")
if isControllerActive(ControllerManager.GroundController) and groundResult and groundResult.Material ~= Enum.Material.Air then
print("Ground detected, performing jump")
local jumpImpulse = ControllerManager:GetAttribute("JumpImpulse")
ControllerManager.RootPart:ApplyImpulse(jumpImpulse)
character.Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
ControllerManager.ActiveController = ControllerManager.AirController
-- floor receives equal and opposite force
local floor = ControllerManager.GroundSensor.SensedPart
if floor then
floor:ApplyImpulseAtPosition(-jumpImpulse, ControllerManager.GroundSensor.HitFrame.Position)
end
else
print("Jump conditions not met")
end
end
end
ContextActionService:BindAction("Jump", doJump, true, Enum.KeyCode.Space)