I’m making a skydive ability that requires my character to completely freeze.
The first thing I do is freeze my character but for some reason when I set AutoRotate to false nothing happens.
I printed everything but it was all normal. I asked the AI assistant and I got something about the UserGameSettings service and checking RotateType property.
function States:toggleFreeze(char,walkSpeed,jumpPower,autoRotate)
local hum = char.Humanoid
hum.WalkSpeed = walkSpeed or StarterPlayer.CharacterWalkSpeed
hum.JumpPower = jumpPower or StarterPlayer.CharacterJumpPower
hum.AutoRotate = autoRotate or true
end
Skydive
local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local modules = ReplicatedStorage.Modules
local Environment = require(modules.Environment)
local States = require(modules.States)
local Skydive = {}
function Skydive:antigravity(char)
local root = char.HumanoidRootPart
local total = 0
local vf = Instance.new("VectorForce")
vf.Attachment0 = root.RootAttachment
vf.Parent = char
for _,comp in ipairs(char:GetChildren()) do
if comp:IsA("BasePart") then
total += comp:GetMass()
end
end
vf.Force = Vector3.yAxis * workspace.Gravity * total
return vf
end
function Skydive.new(char,ao,direction,lungeTrack)
local root = char.HumanoidRootPart
States:toggleFreeze(char,0,0,false)
local vf = Skydive.antigravity(Skydive,char)
local lv = Instance.new("LinearVelocity")
lv.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
lv.Attachment0 = root.RootAttachment
lv.Parent = root
ao.CFrame = CFrame.lookAlong(root.Position,direction)
lv.VectorVelocity = direction * 1e2
lungeTrack:Play(0.1,1,0)
local impactListener
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = {char}
impactListener = RunService.Heartbeat:Connect(function()
local result = workspace:Raycast(root.Position,direction * 10,params)
if result then
root.AssemblyLinearVelocity = Vector3.zero
lungeTrack:Stop()
lungeTrack:Play()
task.delay(0.05,lv.Destroy,lv)
task.delay(0.05,vf.Destroy,vf)
task.delay(lungeTrack.Length - 0.1,ao.Destroy,ao)
impactListener:Disconnect()
root.Parent.Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
end
end)
repeat task.wait() until not impactListener.Connected
States:toggleFreeze(char)
end
return Skydive