I need to create a total of four raycasts given two Vector3 positions, starting from Position1 and ending at Position2.
I can easily create a raycast to emulate a projectile hit (given two positions) but I need to account for the Radius of the projectile. I figure a quick and simple solution would be to do four raycasts parallel but offset to the original raycast (offset by the radius of the projectile). (making a box is fine I don’t need a perfect circle)
Here is a visualization of the ray given two positions (top image) and the four rays I need (bottom image):
Oh you can just use CFrame.lookAt() to generate the CFrame.
local Pos1 = Vector3.new(12.14, 7.63, 0.62)
local Pos2 = Vector3.new(19.41, 7.63, 0.62)
local Radius = 1.2
local lookAtCF = CFrame.lookAt(Pos1,Pos2)
local upPosition = Pos1 +lookAtCF.UpVector*Radius
local rightPosition = Pos1 +lookAtCF.RightVector*Radius
local downPosition = Pos1 - lookAtCF.UpVector*Radius
local leftPosition = Pos1 - lookAtCF.RightVector*Radius
And here is how CFrame.lookAt() works via the example code they gave on the API which was meant to subsitute CFrame.new(pos1,pos2) but then removed for some reason to promote CFrame.lookAt() I guess. Just if you were curious to how the CFrame.lookAt() is generated.
Native lua implementation of CFrame.lookAt
--This is the same as CFrame.lookAt
local function customLookAt(position,lookAt,upVector)
upVector = upVector or Vector3.new(0,1,0)
local direction = lookAt-position
local rightVector = direction:Cross(upVector)
local newUpVector = rightVector:Cross(direction)
return CFrame.fromMatrix(position,rightVector,newUpVector)
end
If you want to place the rays in a circular approach instead you can use the obtained CFrame.lookAt.UpVector as the new y axis and CFrame.lookAt.RightVector as the x axis.