I made custom controls for a StarterPlayer model that is a sphere, it works just fine in studio but in roblox it does not.
if not game:IsLoaded() then
game.Loaded:Wait()
end
local UserInputService = game:GetService("UserInputService")
local ContextActionService = game:GetService("ContextActionService")
local PLAYER = game.Players.LocalPlayer
local CHARACTER = PLAYER.Character
local jumps = 2
local jumpDebounce = true
local RAYCAST_PARAMS = RaycastParams.new()
RAYCAST_PARAMS.FilterType = Enum.RaycastFilterType.Exclude
RAYCAST_PARAMS.FilterDescendantsInstances = {CHARACTER}
function updateAngularVelocity()
local accel = script:GetAttribute("Acceleration")
local maxSpeed = script:GetAttribute("MaxAngularSpeed")
local part = CHARACTER.PrimaryPart
local direction = Vector3.new(CHARACTER.Humanoid.MoveDirection.z , 0 , -CHARACTER.Humanoid.MoveDirection.x)
local maxvelocity = direction * maxSpeed
local excess = maxvelocity - part.AssemblyAngularVelocity
if maxvelocity.Magnitude > part.AssemblyAngularVelocity.Magnitude then
part.AssemblyAngularVelocity += excess.Unit * accel
else
part.AssemblyAngularVelocity = maxvelocity
end
end
function jump(actionName, inputState, _inputObject)
if jumpDebounce then
jumpDebounce = false
if jumps > 0 and inputState == Enum.UserInputState.Begin then
jumps -= 1
local velocity = CHARACTER.PrimaryPart.AssemblyLinearVelocity
CHARACTER.PrimaryPart.AssemblyLinearVelocity = velocity * Vector3.new(1,0,1) + (Vector3.yAxis * script:GetAttribute("JumpSpeed"))
CHARACTER.PrimaryPart.ParticleEmitter:Emit(script:GetAttribute("Particles"))
script.JumpSound:Play()
if jumps == 0 then
print("DOUBLE")
--Propel character in movedirection
CHARACTER.PrimaryPart.AssemblyLinearVelocity = (CHARACTER.PrimaryPart.AssemblyLinearVelocity * Vector3.new(0,1,0)) + CHARACTER.Humanoid.MoveDirection * script:GetAttribute("DoubleJumpSpeed")
end
task.wait(0.1)
end
jumpDebounce = true
end
end
function landCharacter(position)
jumps = 2
--Snap character to floor
CHARACTER:PivotTo(CFrame.new(position + Vector3.new(0,CHARACTER.PrimaryPart.Size.Y / 2,0)) * CHARACTER:GetPivot() - CHARACTER:GetPivot().Position )
--Set velocity accordingly
CHARACTER.PrimaryPart.AssemblyLinearVelocity = CHARACTER.PrimaryPart.AssemblyLinearVelocity * Vector3.new(1,0,1)
end
function checkFall()
local raycast = workspace:Raycast(CHARACTER.PrimaryPart.Position , -Vector3.yAxis * 3 , RAYCAST_PARAMS)
if raycast then
if (raycast.Position - CHARACTER:GetPivot().Position).Magnitude < 2 then
if math.abs(CHARACTER.PrimaryPart.AssemblyAngularVelocity.Y) > script:GetAttribute("BreakThreshold") then
fallDeath()
end
landCharacter(raycast.Position)
end
end
end
function fallDeath()
warn("You fell from a deadly height")
end
repeat
wait(0.1)
CHARACTER = PLAYER.Character
until CHARACTER
ContextActionService:BindAction("Jump" , jump , true , Enum.KeyCode.Space)
while task.wait() do
workspace.CurrentCamera.CameraSubject = CHARACTER.PrimaryPart
updateAngularVelocity()
if jumps ~= 2 and CHARACTER.PrimaryPart.AssemblyAngularVelocity.Y < 0 then
checkFall()
end
end
print("started")
Everything prints out correctly and the particles work too, but the part does not move at all.
Is this a bug?