I am trying to make a laser part come out out of another part (already made in Workspace) based on the positioning of it. It is not a tool, because I don't want the player's mouse to determine where it shoots. I want it to come out from the direction the part in Workspace is pointing to.
I was then led to lookVector
after a while of researching. I tried using it like this:
--This is just the section where I create the part --It's not important, but it's there in case you need it to study my script. local part = Instance.new("Part", game.Workspace) part.BrickColor = BrickColor.new("Really red") part.FormFactor = "Custom" part.Anchored = true part.CanCollide = false part.Material = "Plastic" part.Transparency = 0.75 --Important Part (I need help on this section) local base = game.Workspace.Base -- Base part local distance = 30 part.Size = Vector3.new(0.02, 0.02, distance) part.CFrame = CFrame.new(base.CFrame.p, base.CFrame.lookVector) * CFrame.new(0, 0, distance/2)
The problem is when I used lookVector
like that, it points at a completely different direction and angle from where the base part is pointing to.
If I take out the lookVector
part and only have one parameter in the CFrame.new()
method, it only comes out in the positive z-direction regardless of where the base part is pointing.
I tried reading up more on lookVector
, but the ROBLOX Wiki didn't have enough information for me to learn more about it. Any ideas on how I can do this?
I think you don't mean part.CFrame = CFrame.new(base.CFrame.p, base.CFrame.lookVector) * CFrame.new(0, 0, distance/2)
. You probably mean part.CFrame = base.CFrame * CFrame.new(0, 0, distance/2)
.
Let me explain - CFrame.new(Vector3 position, Vector3 lookat)
returns a CFrame at position
, pointing towards lookat
. This is a problem for you, because in that instance the lookVector is very close to 0,0,0