I made a hamster ball but my player teleports on top of the ball instead of inside
This is the hamster ball in explorer: https://gyazo.com/181efcf03bdea73deb44eac046e73996
Help!
local CHARACTERS = game.Workspace:WaitForChild("CHARACTERS")
local modules = game:GetService("ReplicatedStorage"):WaitForChild("Modules")
local ballControllerClass = require(modules:WaitForChild("BallController"))
local ballObject = ballControllerClass.new(game.Players.LocalPlayer)
game:GetService("ContextActionService"):BindAction("DriveBall", function(action, state, input)
if (state == Enum.UserInputState.Begin) then
local dist = ballObject:DistanceFromCharacter()
if (dist < -3 or dist > 0) then
return
end
ballObject:SetActive(not ballObject.IsActive)
end
end, false, Enum.KeyCode.E)
function ballObject:GetGravityVector(oldGravity)
if (not self.IsActive) then
return Vector3.new(0, 1, 0)
end
local ball = self.Ball
local length = ball.Size.x/3 + 5
local vel = ball.Velocity
local hVel = vel - vel:Dot(oldGravity)*oldGravity
local dirF = hVel:Dot(hVel) > 0 and hVel.Unit or Vector3.new(0, 0, 0)
local ray = Ray.new(ball.Position, dirF*length)
local hit, pos, normal = game.Workspace:FindPartOnRayWithIgnoreList(ray, {self.Ball, self.Character})
if (hit and not hit:IsDescendantOf(CHARACTERS)) then
return normal
else
local ray = Ray.new(ball.Position, -oldGravity*length)
local hit, pos, normal = game.Workspace:FindPartOnRay(ray, self.Character)
if (hit and not hit:IsDescendantOf(CHARACTERS)) then
return normal
else
return oldGravity
end
end
end

1 comment
Make sure the ball is empty inside...