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

Part that travels along a ray?

Asked by 9 years ago

I'm trying to make a part travel along a ray, I know how to make the ray, and I can make a part that goes along the entire ray like a regular raycast gun. But I'm trying to make a part that starts at the beginning of the ray, and moves along the ray till the end of the ray without appearing as a line.

local look = pilot.Character:findFirstChild("Shuttle").Cannon.CFrame.lookVector
local start = pilot.Character:findFirstChild("Shuttle").Cannon.CFrame.p
local ray = Ray.new(start,look.unit*300)
local ignore = {pilot.Character:findFirstChild("Shuttle"),pilot.Character}
local hit, position = game.Workspace:FindPartOnRayWithIgnoreList(ray,ignore)

local distance = (position - start).magnitude
local RB = Instance.new("Part", game.Workspace)
RB.Name = "Laser"
RB.Material = "SmoothPlastic"
RB.FormFactor = "Custom"
RB.TopSurface = "Smooth"
RB.BottomSurface = "Smooth"
RB.Anchored = true
RB.CanCollide = false
RB.Transparency = 0.5
RB.BrickColor = BrickColor.new("Really blue")
RB.Reflectance = 0.4
RB.Size = Vector3.new(0.2, 0.2, distance)
RB.CFrame = CFrame.new(position, start) * CFrame.new(0, 0, -distance/2)

But if I change the distance to a number in the line below, then the part just spawns at the end of the ray instead of spawning at the beginning and traveling along the ray.

RB.Size = Vector3.new(0.2, 0.2, distance)
0
Okay, didn't know how to do that, thanks. commanderCody246 0 — 9y
0
Can you also describe what it is that you want? "Starts" and "follows" aren't very clear. Do you want this to happen over time? Does the part actually move? Change size? Where does it start? How big is it when it starts? Where does it stop? etc... BlueTaslem 18071 — 9y
0
Yes, the part moves along the ray, over time similar to a projectile moving. It doesn't change size. I'll edit the existing code to include more parts that should help and define where it starts. and it ends where the ray ends. commanderCody246 0 — 9y

Answer this question