I’m tryna to use raycasting to detect when a ball has hit a surface, but for some reason it’s inaccurate most of the time.
Black Leaf - Roblox Studio (gyazo.com)
local bvel = Instance.new("BodyVelocity",Pebble)
bvel.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
bvel.Velocity = Pebble.CFrame.lookVector * 150
bvel.P = 1250
local Ignore = {Character,game.Workspace.Alive,workspace.Areas,workspace.GarbageCollector}
function ray(startpos, endpos, dis)
local test = Ray.new(startpos, CFrame.new(startpos, endpos).lookVector * dis)
local hit, pos, sf = game.Workspace:FindPartOnRayWithIgnoreList(test,Ignore)
return hit, pos, sf
end
local check
check = game["Run Service"].Heartbeat:connect(function()
local h, p, sf = ray(Pebble.Position, Pebble.CFrame * CFrame.new(0,0,-0.4).p, 10)
if h and not exploded then
exploded = true
Pebble.Position = h.Position
Pebble.Anchored = true
Pebble.pebble1:Play()
Pebble.Explode.ParticleEmitter:Emit(20)
bvel:Destroy()
game.Debris:AddItem(Pebble,1)
end
end)