Hey, I have a rock that the player can roll around. The problem is that when the player tries to roll it up a hill or ramp, it just wont do it.
Here’s the script:
local boulder = script.Parent
local pushForce = 500
local friction = 0.3
local maxForce = 8000
boulder.Touched:Connect(function(hit)
local character = hit.Parent
local player = game.Players:GetPlayerFromCharacter(character)
if player then
local bodyForce = Instance.new("BodyVelocity")
bodyForce.MaxForce = Vector3.new(maxForce, maxForce, maxForce)
bodyForce.Velocity = character.PrimaryPart.CFrame.LookVector * pushForce
bodyForce.Parent = boulder
wait(0.5)
bodyForce:Destroy()
end
end)
game:GetService("RunService").Stepped:Connect(function(_, deltaTime)
local velocity = boulder.Velocity
if velocity.Magnitude > 0 then
local deceleration = velocity * -friction * deltaTime
boulder.Velocity = velocity + deceleration
end
end)
Here’s a video of the problem (idk why its so low quality):
If anyone knows how to fix this, please send ur ideas.
The Ramp or ball is probably too large for the ball to roll but here is the script:
local boulder = script.Parent
local pushForce = 500
local friction = 0.3
local maxForce = 8000
local db = false
local runService = game:GetService("RunService")
local players = game:GetService("Players")
runService.Heartbeat:Connect(function(deltaTime)
if boulder.Velocity.Magnitude > 0 then
local deceleration = boulder.Velocity * -friction * deltaTime
boulder.Velocity = boulder.Velocity + deceleration
end
end)
while runService.Heartbeat:Wait() do
local touchingParts = workspace:GetPartsInPart(boulder)
for _, part in ipairs(touchingParts) do
local character = part.Parent
local player = players:GetPlayerFromCharacter(character)
if player and not db and character:FindFirstChild("Humanoid") and character.PrimaryPart then
db = true
local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.MaxForce = Vector3.new(maxForce, maxForce, maxForce)
bodyVelocity.Velocity = character.PrimaryPart.CFrame.LookVector * pushForce
bodyVelocity.Parent = boulder
task.wait(0.5)
db = false
bodyVelocity:Destroy()
end
end
end