Hello,is everyone doing okay?
Well i have stumbled across a problem while trying to make a paint gun.
i need to cast a ray to the surface once the ball of paint hits the object so i know the position and rotation to make the splat so for example the white wall is the (wall) and the green object is the ball of paint and the yellow object is the splat
this is what should happen:
this is what’s happening:
this is my current code:
it=Instance.new
v3=Vector3.new
cf=CFrame.new
ca=CFrame.Angles
gun=script.Parent
hand=script.Parent.Handle
props={
orange=
{
Color=Color3.fromRGB(253,102,0)
},
blue=
{
Color=Color3.fromRGB(0,120,255)
},
white=
{
Color=Color3.fromRGB(200,200,200)
}
}
modes={"orange","blue","white"}
curmode=modes[1]
function makeball()
local sp=it("Part",script)
sp.Velocity=hand.CFrame.LookVector*40+hand.CFrame.UpVector*5
sp.CFrame=hand.CFrame
sp.Size=v3(3,3,3)
sm=it("SpecialMesh",sp)
sm.MeshType="Sphere"
sp.Name="paint_ball"
sp.Color=props[curmode].Color
sp.Material="Glass"
local hashit=false
sp.Touched:Connect(function(hit)
if hit.Parent==nil then return end
if hit.Parent~=script and hit.Parent~=owner.Character and hit~= hand and hit.Name~="Handle" and not hashit then
hashit=true
--print(hit.Name)
local target=(hit.CFrame.p-sp.CFrame.p).unit*100
local ray=Ray.new(sp.CFrame.p,target)
local hit,pos,norm=workspace:FindPartOnRay(ray)
if hit then
--print(hit)
local s=it("Part",script)
s.Anchored=true
s.Name="_splat"
s.CanCollide=false
s.Color=sp.Color
s.Material="Glass"
s.Size=v3(8,8,0.001)
s.CFrame=CFrame.new(pos,pos+norm*30)
Debris:AddItem(sp,.1)
pcall(function() sp:Destroy() end)
end
end
end)
Debris:AddItem(sp,3)
end
gun.Activated:Connect(function()
makeball()
end)
any help is appreciated,i literally have no idea how to make the splat be on that position