local player = game.Players.LocalPlayer
local function onCharacterAdded(character)
-- Ожидаем загрузки PrimaryPart
local primaryPart = character:WaitForChild("HumanoidRootPart")
-- Создаем сферу и заменяем текущий персонаж
local sphere = Instance.new("Part")
sphere.Shape = Enum.PartType.Ball
sphere.Size = Vector3.new(5, 5, 5)
sphere.Anchored = false
sphere.CanCollide = true
sphere.Position = primaryPart.Position
sphere.Parent = workspace
-- Перемещаем персонажа в сферу и отключаем коллизии персонажа
character:MoveTo(sphere.Position)
for _, part in ipairs(character:GetChildren()) do
if part:IsA("BasePart") then
part.CanCollide = false
part.Transparency = 1 -- Делаем части персонажа невидимыми
elseif part:IsA("Accessory") then
part.Handle.CanCollide = false
part.Handle.Transparency = 1
end
end
-- Привязываем персонажа к сфере
local weld = Instance.new("WeldConstraint")
weld.Part0 = sphere
weld.Part1 = primaryPart
weld.Parent = sphere
-- Управление
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local speed = 50
local function onInputBegan(input, isProcessed)
if isProcessed then return end
local direction = Vector3.new()
if input.KeyCode == Enum.KeyCode.W then
direction = Vector3.new(0, 0, -1)
elseif input.KeyCode == Enum.KeyCode.S then
direction = Vector3.new(0, 0, 1)
elseif input.KeyCode == Enum.KeyCode.A then
direction = Vector3.new(-1, 0, 0)
elseif input.KeyCode == Enum.KeyCode.D then
direction = Vector3.new(1, 0, 0)
end
local force = Instance.new("BodyVelocity")
force.Velocity = direction * speed
force.MaxForce = Vector3.new(4000, 0, 4000)
force.Parent = sphere
wait(0.1)
force:Destroy()
end
UserInputService.InputBegan:Connect(onInputBegan)
-- Управление джойстиком
local function onSteer(actionName, inputState, input)
if inputState == Enum.UserInputState.Change then
local direction = Vector3.new(input.Position.x, 0, -input.Position.y)
local force = Instance.new("BodyVelocity")
force.Velocity = direction * speed
force.MaxForce = Vector3.new(4000, 0, 4000)
force.Parent = sphere
wait(0.1)
force:Destroy()
end
end
game:GetService("ContextActionService"):BindAction("Steer", onSteer, true, Enum.PlayerActions.CharacterForward, Enum.PlayerActions.CharacterBackward, Enum.PlayerActions.CharacterLeft, Enum.PlayerActions.CharacterRight)
end
player.CharacterAdded:Connect(onCharacterAdded)
-- Если персонаж уже существует, вызываем функцию сразу
if player.Character then
onCharacterAdded(player.Character)
end
local player = game.Players.LocalPlayer
local function onCharacterAdded(character)
-- Ожидаем загрузки PrimaryPart
local primaryPart = character:WaitForChild("HumanoidRootPart")
-- Создаем сферу и заменяем текущий персонаж
local sphere = Instance.new("Part")
sphere.Shape = Enum.PartType.Ball
sphere.Size = Vector3.new(5, 5, 5)
sphere.Anchored = false
sphere.CanCollide = true
sphere.Position = primaryPart.Position
sphere.Parent = workspace
-- Перемещаем персонажа в сферу и отключаем коллизии персонажа
character:MoveTo(sphere.Position)
for _, part in ipairs(character:GetChildren()) do
if part:IsA("BasePart") then
part.CanCollide = false
part.Transparency = 1 -- Делаем части персонажа невидимыми
elseif part:IsA("Accessory") then
part.Handle.CanCollide = false
part.Handle.Transparency = 1
end
end
-- Привязываем персонажа к сфере
local weld = Instance.new("WeldConstraint")
weld.Part0 = sphere
weld.Part1 = primaryPart
weld.Parent = sphere
-- Добавляем BodyGyro для стабилизации шара
local bodyGyro = Instance.new("BodyGyro")
bodyGyro.MaxTorque = Vector3.new(4000, 4000, 4000)
bodyGyro.P = 3000
bodyGyro.CFrame = sphere.CFrame
bodyGyro.Parent = sphere
-- Добавляем BodyAngularVelocity для вращения шара
local bodyAngularVelocity = Instance.new("BodyAngularVelocity")
bodyAngularVelocity.MaxTorque = Vector3.new(4000, 4000, 4000)
bodyAngularVelocity.P = 3000
bodyAngularVelocity.Parent = sphere
-- Управление
local UserInputService = game:GetService("UserInputService")
local speed = 50
local function onInputBegan(input, isProcessed)
if isProcessed then return end
local direction = Vector3.new()
if input.KeyCode == Enum.KeyCode.W then
direction = Vector3.new(0, 0, -1)
elseif input.KeyCode == Enum.KeyCode.S then
direction = Vector3.new(0, 0, 1)
elseif input.KeyCode == Enum.KeyCode.A then
direction = Vector3.new(-1, 0, 0)
elseif input.KeyCode == Enum.KeyCode.D then
direction = Vector3.new(1, 0, 0)
end
bodyAngularVelocity.AngularVelocity = direction * speed
end
local function onInputEnded(input, isProcessed)
if isProcessed then return end
if input.KeyCode == Enum.KeyCode.W or input.KeyCode == Enum.KeyCode.S or input.KeyCode == Enum.KeyCode.A or input.KeyCode == Enum.KeyCode.D then
bodyAngularVelocity.AngularVelocity = Vector3.new(0, 0, 0)
end
end
UserInputService.InputBegan:Connect(onInputBegan)
UserInputService.InputEnded:Connect(onInputEnded)
-- Управление джойстиком
local function onSteer(actionName, inputState, input)
if inputState == Enum.UserInputState.Change then
local direction = Vector3.new(input.Position.x, 0, -input.Position.y)
bodyAngularVelocity.AngularVelocity = direction * speed
elseif inputState == Enum.UserInputState.End then
bodyAngularVelocity.AngularVelocity = Vector3.new(0, 0, 0)
end
end
game:GetService("ContextActionService"):BindAction("Steer", onSteer, true, Enum.PlayerActions.CharacterForward, Enum.PlayerActions.CharacterBackward, Enum.PlayerActions.CharacterLeft, Enum.PlayerActions.CharacterRight)
end
player.CharacterAdded:Connect(onCharacterAdded)
-- Если персонаж уже существует, вызываем функцию сразу
if player.Character then
onCharacterAdded(player.Character)
end