so i have a blow gun that shoots a dart towards a target but when i spawn the dart, it’s orientation isnt completely straight; which is how i want it to be.
i want the dart to be 90 degrees; parallel to the baseplate if you will. how would you do that? i appreciate any help
local function makeDart90Degrees()
end
local function sendDartToBlowgun()
local handleCFrame = blowgun:GetPivot()
local endPart = blowgun.endpart
local offsetZ = (blowgun.Handle.Size.Z / 2) + (endPart.Size.Z) + (blowgun.Handle.Size.Z / 4.5)
local blowgunEndCFrame = handleCFrame * CFrame.new(0,0,-offsetZ)
local mouseScreenPosition = game:GetService("UserInputService"):GetMouseLocation()
local camera = workspace.CurrentCamera
local rotation = CFrame.Angles(math.rad(90), 0, 0)
local mouseRay = camera:ViewportPointToRay(mouseScreenPosition.X, mouseScreenPosition.Y, 0)
local rayEndPoint = mouseRay.Origin + mouseRay.Direction * RAY_DISTANCE
local lookat = CFrame.lookAt(blowgunEndCFrame.Position, rayEndPoint)
local finalCFrame = lookat * CFrame.new(0,0,0) * rotation
return finalCFrame, rayEndPoint, blowgunEndCFrame
end
You can lock the Y axis of CFrame.lookAt so the two points are on XZ plane parallel to the baseplate, use the same rayEndPoint XZ coordinates but make the Y coordinate the same as the origin blowgunEndCFrame.Position.Y .
Below uses CFrame.new() which does the same thing as CFrame.lookAt unless you were the include the third parameter of CFrame.lookAt which is not necessary for this scenario.