Top.Mail.Ru
Ответы
Аватар пользователя
Аватар пользователя
Аватар пользователя
Аватар пользователя
Программирование
+2

Дайте скрипт на роблокс

Можете дать скрипт на притяжение игроков к сфере я хочу сделать режим типо про планету а она круглая и я не хочу что бы игрок падал когда доходил до соседнего полюса а что бы везде ходил и как бы был прикреплен к планете знаете такой скрипт ?

По дате
По рейтингу
Аватар пользователя
Мыслитель
12345678910111213141516171819202122232425
 local player = game.Players.LocalPlayer 
local planet = game.Workspace.Planet 
 
local function onStep() 
    local distance = (player.Character.HumanoidRootPart.Position - planet.Position).Magnitude 
    local force = (planet.Position - player.Character.HumanoidRootPart.Position).Unit * (distance / 10) 
    player.Character.HumanoidRootPart.Velocity = force 
end 
 
game.Players.LocalPlayer.CharacterAdded:Connect(function() 
    game.Players.LocalPlayer.Character.HumanoidRootPart.Anchored = true 
end) 
 
game.Workspace.Planet.Touched:Connect(function(hit) 
    if hit.Parent:FindFirstChild("Humanoid") then 
        local player = game.Players:FindFirstChild(hit.Parent.Name) 
        if player then 
            player.Character.HumanoidRootPart.Anchored = true 
        end 
    end 
end) 
 
game.Players.LocalPlayer.CharacterRemoving:Connect(function() 
    game.Players.LocalPlayer.Character.HumanoidRootPart.Anchored = false 
end) 
Аватар пользователя
Просветленный
1234567891011121314151617181920212223242526272829303132333435363738394041424344
 -- Прикрепите этот скрипт к объекту, который представляет вашу планету 
 
local Planet = script.Parent -- Убедитесь, что этот скрипт прикреплен к объекту-планете 
 
local gravityStrength = 500 -- Сила гравитации, можете настроить по своему вкусу 
local gravityRange = 100 -- Радиус действия гравитации 
 
local function attractPlayer(player) 
    local character = player.Character or player.CharacterAdded:Wait() 
    local humanoid = character:WaitForChild("Humanoid") 
    local rootPart = character:FindFirstChild("HumanoidRootPart") 
     
    if not rootPart then return end 
     
    local direction = (rootPart.Position - Planet.Position).Unit 
    local force = direction * gravityStrength 
     
    humanoid:ChangeState(Enum.HumanoidStateType.FallingDown) 
    humanoid.WalkSpeed = 0 -- Можно оставить или убрать, чтобы игроки не могли двигаться 
     
    coroutine.wrap(function() 
        while rootPart.Position:DistanceTo(Planet.Position) <= gravityRange do 
            humanoid:AddForce(force) 
            wait(0.1) -- Частота обновления притяжения, можете настроить 
        end 
         
        humanoid.WalkSpeed = 16 -- Возвращаем обычную скорость ходьбы 
    end)() 
end 
 
for _, player in ipairs(game.Players:GetPlayers()) do 
    attractPlayer(player) 
end 
 
game.Players.PlayerAdded:Connect(function(player) 
    attractPlayer(player) 
end) 
 
game.Players.PlayerRemoving:Connect(function(player) 
    -- Опционально, если хотите остановить притяжение при выходе игрока 
    local character = player.Character or player.CharacterAdded:Wait() 
    local humanoid = character:WaitForChild("Humanoid") 
    humanoid.WalkSpeed = 16 
end)