Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

Raycasting part moves past Starting Part?

Asked by
Muoshuu 580 Moderation Voter
9 years ago

I've set up a raycasting system, and everything works fine except the part moves past the starting position.

Pretty much ----PartA-----------------------PartB

Here's the code

function Fire(Gun,Unit)
    local Part=Instance.new("Part")
    local Distance=(Gun.Position-Unit.Recolor.Position).magnitude
    local Ray=Ray.new(Gun.Position,(Unit.Recolor.Position-Gun.Position).unit*300)
    local Hit,Position=workspace:FindPartOnRay(Ray,script.Parent)
    Part.Name="Raycast_"..math.random(1,2000000000)
    Part.Anchored=true
    Part.CanCollide=false
    Part.TopSurface="Smooth"
    Part.BottomSurface="Smooth"
    Part.FormFactor="Custom"
    Part.Size=Vector3.new(.2,.2,Distance)
    Part.CFrame=CFrame.new(Position,Gun.CFrame.p)*CFrame.new(0,0,-Distance/2)
    Part.BrickColor=Team.TeamColor
    local Mesh=Instance.new("BlockMesh",Part)
    Mesh.Scale=Vector3.new(.5,.5,1)
    Part.Parent=workspace
    coroutine.wrap(function()
        wait(.5)
        Part:destroy()
    end)()
end

Here's a picture

0
I'm going to assume "Unit" is the target? Discern 1007 — 9y
0
Yes Muoshuu 580 — 9y

Answer this question