im trying to create a recreation of last prism, so i started with the bare bones on figuring out how to get a raycast to have offset, similar to how shotguns have bullet spread, but thats randomized, i wanted it to be able to have a fixed offset to be able to replicate it just like the one in the game
the script tht i have so far, inside a tool as a local script
-- LocalScript
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local camera = game.Workspace.CurrentCamera
local humanoidRootPart = player.Character and player.Character:WaitForChild("HumanoidRootPart")
-- Customizable fixed offset for raycast direction (in degrees)
local offsetX = 1 -- Fixed offset on the X-axis (degrees)
local offsetY = 1 -- Fixed offset on the Y-axis (degrees)
local offsetZ = 1 -- Fixed offset on the Z-axis (degrees)
-- Create a function to perform the raycast and create the part
local function createRaycastPart()
if not humanoidRootPart then return end
-- Raycast from HumanoidRootPart to the mouse position
local mousePosition = mouse.Hit.p
local direction = (mousePosition - humanoidRootPart.Position).unit * 500 -- Ray length
-- Apply fixed offset to the raycast direction in X, Y, and Z
local fixedOffset = CFrame.Angles(math.rad(offsetX), math.rad(offsetY), math.rad(offsetZ)).LookVector
local offsetDirection = direction + fixedOffset -- Apply the fixed offset to the direction vector
-- Perform the raycast with the offset direction
local raycastResult = workspace:Raycast(humanoidRootPart.Position, offsetDirection * 500)
-- If the ray hits something, we can use that hit position
local hitPosition = raycastResult and raycastResult.Position or mousePosition
-- Create the part at the hit position
local part = Instance.new("Part")
part.Size = Vector3.new(2, 2, 2) -- Size of the part
part.Position = hitPosition
part.Anchored = true
part.CanCollide = false
part.Parent = workspace
-- Make the part face the player (HumanoidRootPart)
local directionToPlayer = (humanoidRootPart.Position - part.Position).unit
local lookAtRotation = CFrame.lookAt(part.Position, part.Position + directionToPlayer)
-- Apply the custom offset rotation to the part (optional)
local offsetRotation = CFrame.Angles(math.rad(0), math.rad(0), math.rad(0)) -- Default (can be customized)
part.CFrame = lookAtRotation * offsetRotation
end
-- Call the function to create the part when the player clicks (or some other trigger)
mouse.Button1Down:Connect(function()
createRaycastPart()
end)