How would i make part size fixed to where its facing

this is kinda confusing question to ask but i think it’ll be easier for me to draw it out

so basically, i want to create a part that is the same length, so the part will start a starting position
and then it’ll look at a part at the end position

the green dot is the starting position, and the red dot is the end position


so here’s an image of what im working on



and this transparent blue part, i want the edge to at the center of the green part like this
image
and i also want to keep the lenght of the blue part to be constant

and i want it to face the red part no matter where it is

here’s my script so far
it does faces the red part
but the side of the blue part doesn’t start at the center of the green part

local hitbox = script.Parent
local start = workspace.Start
local target = workspace.target

local startPosition = start.Position
local endPosition = target.Position

hitbox.CFrame =  CFrame.new(startPosition, endPosition)

im not sure if this is possible, or if my question doesn’t make sense

Are you wanting essentially a laser that starts from one point and ends at the other? Or do you want a limited range beam that starts at one point, faces the target point, but only goes out a set distance in that direction?

Either way, you’ll want to use the CFrame constructors. CFrame.new ( Vector3 pos, Vector3 lookAt ) to get the start position and orientation. Then you’ll set the size to either the length you want or the magnitude between the start and end points, then offset the part’s position relative to half it’s size to move it to the center or to at least start at the starting point.

i want a limited beam, that starts from the green part, but like it’s limited by a certain distance, but faces the red part

You can use PivotPoints for this.

PivotPoints is the point which a part is rotated around on.

You can set the GreenPart’s PivotPoint to be in the center, and the BluePart’s PivotPoint to be in the end where you like it to be. And then just make the blue part face towards the red part.

So here’s an example:

local length = 10

local folder = script.Parent
local start = folder:WaitForChild('Start')
local target = folder:WaitForChild('Target')
local beam = folder:WaitForChild('Beam')

function UpdateBeam()
	-- Actual math here
	beam.Size = Vector3.new(1,1,length)
	beam.CFrame = CFrame.new(start.Position,target.Position) * CFrame.new(0,0,-length/2)
end

while true do
	UpdateBeam()
	task.wait()
end

Example model here:
Beam Example.rbxm (3.6 KB)

1 Like

yes thats what im looking for! thank you!