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

How do I create a Raycast between two parts?

Asked by 4 years ago
Edited 4 years ago

I have a script below that I am using as a reference. I am wondering how I can make a Ray between two parts I have in Workspace. The parts are named "Part" and "Part1".

Reference -

local Ray = Ray.new(game.Workspace.vislbIe.HumanoidRootPart.Position, game.Workspace.vislbIe.HumanoidRootPart.Position - Vector3.new(0,3,0))

local part = game.Workspace:FindPartOnRay(Ray,game.Workspace.vislbIe)

--[[
 (I am not wanting to create the Ray using the same method as this script, I simply wanted to see how this stuff works)
]]--

Now, I want to make a Ray begin on Part, then end at Part1. Here is a script from Roblox Wiki, this script is how I want to make my ray, minus the Tool handle.

local ray = Ray.new(
    Weapon.Handle.CFrame.p,                           -- origin
    (mouse.Hit.p - Weapon.Handle.CFrame.p).unit * 500 -- direction
) 
local ignore = game.Players.LocalPlayer.Character
local hit, position, normal = Workspace:FindPartOnRay(ray, ignore)

Any solutions?

http://prntscr.com/ntni5s

Screenshot of parts above.

1 answer

Log in to vote
3
Answered by 4 years ago
Edited 4 years ago

Ray.new has 2 arguments, 1st one is the starting position of the ray, the second the vector of the ray including length.

in your script

local startPos = Part.Position
local rayVector = Part1.Position - Part.Position

then,

local ray = Ray.new(startPos, rayVector)
1
9 months later.. I want to thank you very much! I never really understood this until now. Thank you! IDKBlox 349 — 4y
Ad

Answer this question